The following code works... but it doesnt...
Ok what i mean is that im populating 2 GridViews in the exactly the same manner but one of them doesnt work...
QUOTE
A field or property with the name 'COMPANY_TYPE' was not found on the selected data source.
. But when i display the data source ... there Company_Type is staring right in my face, it does this for all the fields.
so heres the definition of the GridView
CODE
<asp:GridView ID="gv_Companies" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="gv_Companies_SelectedIndexChanged">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField SelectText="View" ShowSelectButton="True" />
<asp:BoundField DataField="COMPANY_TYPE" HeaderText="Company Type" />
<asp:BoundField DataField="COMPANY_NAME" HeaderText="Company Name" />
<asp:BoundField DataField="CONTACT_PERSON" HeaderText="Contact Person" />
<asp:BoundField DataField="OFFICE_NUMBER" HeaderText="Office #" />
<asp:BoundField DataField="PRIMARY_EMAIL" HeaderText="Email" />
<asp:BoundField DataField="OFFICE_FAX" HeaderText="Fax #" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
the code to fetch the data, transform it into something the GridView can use and bind the XML datasource:
CODE
protected void Page_Load(object sender, EventArgs e)
{
((MasterPg)Master).InitMP();
((MasterPg)Master).setActiveNavBarPanel();
string message = "<Message><Company><OwnerGUID>";
if (RadioButtonList1.SelectedValue.ToLower().Equals("own"))
message += ((MasterPg)Master).UserGUID;
else
message += "*";
message += "</OwnerGUID>" +
"<CompanyGUID/>" +
"<COMPANY_TYPE/>" +
"<COMPANY_NAME/>" +
"<CONTACT_PERSON/>" +
"<OFFICE_NUMBER/>" +
"<PRIMARY_EMAIL/>" +
"<OFFICE_FAX/>" +
"</Company></Message>";
((MasterPg)Master).PageData = ((MasterPg)Master).getService().Search(message);
// ((MasterPg)Master).MessageBox(StaticOperations.XmlDataStringToXmlAttributeString(((MasterPg)Master).PageData));
BindGridView();
gv_Companies.Visible = true;
StaticOperations.CreateDBEvent(((MasterPg)Master).UserGUID, "Personal Companies Page View");
}
private void BindGridView()
{
XmlDataSource XDS = new XmlDataSource();
XDS.Data = StaticOperations.XmlDataStringToXmlAttributeString(((MasterPg)Master).PageData);
gv_Companies.DataSource = XDS;
gv_Companies.DataBind();
}
where PageData is just a string residing on the MasterPage.
the XML returned from getService().Search(string) is exactly as sent just with data in all the fields.
oh and
CODE
public static string XmlDataStringToXmlAttributeString(string XmlString)
{
string tempa = "<Message>";
XmlDocument XDoc = new XmlDocument();
XDoc.InnerXml = XmlString;
if (!XDoc.HasChildNodes)
{
throw new Exception("Malformed Xml String");
}
XmlElement XRootElem = XDoc.DocumentElement;
XmlNodeList XBaseNodeList = XRootElem.ChildNodes;
foreach (XmlNode XBaseNode in XBaseNodeList)
{
tempa += "<"+XBaseNode.Name;
foreach (XmlNode XDataNode in XBaseNode.ChildNodes)
{
tempa += " " + XDataNode.Name + "=\"" + XDataNode.InnerText + "\"";
}
tempa += "/>";
}
tempa += "</Message>";
return tempa;
}
the other operation that it uses to transform the XML.
Any one got ideas?
one last thing, in XML, does it matter what order the attributes are in? thats about the only thing i can think of that could possibly be going wrong because <Company_Type/> is the third attribute in the XML but the first required field in the GridView.
This post has been edited by hyperionza: 9 Oct, 2007 - 02:42 AM