Problem filling a DataGrid
Rich,
1) Have you tried adding some auditing to make sure you are getting through the
code?
2) Have you checked the html source of hat you are generating to make sure it
looks ok?
3) How about trying loading the XML directly into a dataset instead of using
your own logic? Or using an XML DOM instead of the reader?
The biggest issue I see is that your code is extremely sensitive to the specific
results you are getting back. If it's not formatted exactly as you are
expecting, you will get different results.
Matt Parks
MVP - Microsoft CRM
----------------------------------------
----------------------------------------
Hello,
I can´t fill a DataGrid with a XmlTextReader. I retrieve the quotes for
one AccountId. It worked fine. And then try to put this in a DataGrid thru a
DataSource, but doesn´t work.
It worked great in my develope environment, but in production the page
open blank and nothing happend, no timeout, no error messeges.
My code is:
strColumnSetXml = "<columnset>";
strColumnSetXml += "<column>name</column>";
strColumnSetXml += "<column>statecode</column>";
strColumnSetXml += "<column>totalamount</column>";
strColumnSetXml += "<column>quoteid</column>";
strColumnSetXml += "</columnset>";
Microsoft.Crm.Platform.Proxy.CObjectName objName = new
Microsoft.Crm.Platform.Proxy.CObjectName();
objName.Id = unAccountId;
objName.Type = Microsoft.Crm.Platform.Proxy.ObjectType.otAccount;
int[] arrCodes = new int[]
{Microsoft.Crm.Platform.Types.QUOTE_STATE.QS_DRAFT ,
Microsoft.Crm.Platform.Types.QUOTE_STATE.QS_ACTIVE };
strResultsXml = quote.RetrieveByObject (userAuth, objName, arrCodes,
strColumnSetXml);
XmlTextReader aReader = new XmlTextReader(new StringReader(strResultsXml));
aReader.WhitespaceHandling = WhitespaceHandling.None;
dgQuotes.DataSource = CreateDataSource(aReader);
dgQuotes.DataBind();
The function is:
private ICollection CreateDataSource(XmlTextReader unReader)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("name", typeof(string)));
dt.Columns.Add(new DataColumn("statecode", typeof(string)));
dt.Columns.Add(new DataColumn("totalamount", typeof(double)));
dt.Columns.Add(new DataColumn("quoteid", typeof(string)));
try
{
while (unReader.Read())
{
if (unReader.HasValue)
{
dr = dt.NewRow();
dr[0] = unReader.Value;
while (!unReader.HasAttributes)
unReader.Read();
dr[1] = unReader.GetAttribute("name");
unReader.Read();
unReader.Read();
while (!unReader.HasValue)
unReader.Read();
dr[2] = unReader.Value.Replace(".", ",");
unReader.Read();
unReader.Read();
while (!unReader.HasValue)
unReader.Read();
dr[3] = unReader.Value;
dt.Rows.Add(dr);
txtHayDatos.Text = "Si";
}
}
Session["Source"] = dt;
DataView dv = new DataView(dt);
return dv;
}
catch (Exception err)
{
// Process other errors here
string strErrorMsg = ("ErrorMessage: " + err.Message );
lblTitulo.Text = strErrorMsg;
return null;
}
}
Thanks!
|