问题描述
我有一个包含许多字段的网格视图,这里我正在从XML文件中检索数据,并且还希望从表中再获取一列.我怎么能从桌子上拿走呢?
这是我尝试从XML文件检索数据的以下代码.
代码隐藏
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
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代码
ASPX code
<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>
在此PIPCODE
标签中,我要从sql服务器获取数据.
如果XML pipno
等于我的表pipno
,那么我想检索pipno
的等效代码.
以及如何编写查询以从表中选择pipcode
的查询,因为我想从XML中获取pipno
并与SQL匹配,然后我要从表中选择等效的pipcode
并应在最后一列中查看网格视图.
如果pipcode
可用,则注释等于OK,如果pipno
不可用,则注释等于NOT IN DB这样.
为此发布解决方案.
预先感谢.
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.
推荐答案
这篇关于如何从XML数据和sql表数据填充网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!