Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid view that contain many fields, here I am retrieving data from XML file and want to take one more column from the table also. how can i take that from the table.

This is the below code I have tried to retrieve data from XML file.
CODE BEHIND
C#
protected void btnviewdata_Click(object sender, EventArgs e)
{
    GridView1.Visible = true;
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TNVKP_8;Integrated Security=True");
    con.Open();
    DataSet reportData = new DataSet();
    reportData.ReadXml(Server.MapPath("XMLFILENAME.xml"));
    GridView2.DataSource = reportData;
    GridView2.DataBind();
    con.Close();
}

ASPX code
ASP.NET
<asp:GridView ID="GridView1" runat="server" Width="96%" PageSize="10" AutoGenerateColumns="False">
                    <Columns>                               
            <asp:TemplateField HeaderText="Select">
                <ItemTemplate>
                    <asp:CheckBox ID="chkbox" runat="server"></asp:CheckBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="TALLY_REC_ID_CODE" HeaderText="Tally_No" />
            <asp:BoundField DataField="CLUSTER_ID" HeaderText="Cluster_ID"/>
            <asp:BoundField DataField="UNIT_TYPE" HeaderText="Unit_Type" />
            <asp:BoundField DataField="VPRC_ID" HeaderText="VPRC_ID" />
            <asp:BoundField DataField="SHG_ID" HeaderText="SHG_ID" />
            <asp:BoundField DataField="PIP_NO" HeaderText="Pip_No" />
            <asp:BoundField DataField="NAME_OF_THE_MEMBER" HeaderText="Member_Name" />
            <asp:BoundField DataField="TYPE_OF_LOAN" HeaderText="Type_of_Loan" />                  
            <asp:BoundField DataField="PRINCIPAL" HeaderText="Principal" />
            <asp:BoundField DataField="INTEREST" HeaderText="Interest" />
            <asp:TemplateField HeaderText="PipNo.">
                <ItemTemplate>
                    <asp:Label ID="PIPCODE" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Remark">
                <ItemTemplate>
                    <asp:Label ID="lblremark"  runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
                    </asp:GridView>  

Here in this PIPCODE label I want take data from the sql server.

If XML pipno equal my table pipno then I want to retrieve the equivalent code for the pipno.

And how can I write the query to select the pipcode from the table because I want to take the pipno from XML and match with SQL then I want to select the equivalent pipcode from table and should view in the last column of grid view.
If pipcode is available then remark equal to OK, if pipno not available then remark equal to NOT IN DB like that.

Post solution for this.

Thanks in advance.
Posted
Updated 7-Dec-11 2:03am
v2
Comments
suhailnoorpawane 7-Dec-11 6:43am    
Do both xml file and datatable retrieve have same column names
rajrprk 7-Dec-11 7:00am    
not a same column name, XML file i m retriving using the tag name
suhailnoorpawane 7-Dec-11 6:47am    
if they both have merge the data table retrieve and the add the datasource to gridview
rajrprk 7-Dec-11 6:49am    
Please post some sample code with this example i m new to this concept

1-read XML data and store in data-table.
2-read from database and store different data-table and marge both the table
3- bind with ur grid view.
 
Share this answer
 
Hi
1. Read XML data and store in a table
2. Read SQL Data and store in a another table
3. Filter data using LINQ.
4. Merge both table in a custom table which u required to bind with gridview with additional column.

Hope this will help u.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900