在 GridView 中显示名称而不是 Id,其值在不同的 table 中使用 asp.net
Display Name instead of Id in a GridView whose value is there in different table using asp.net
我有一个 GridView,其中我根据选定的客户名称显示网格,在网格中我有一个客户 ID 而不是那个客户 ID 我需要显示其值不同的客户名称 Table如何使用 asp.net 实现它。
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#2A3F54" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" Width="100%" Height="100%" CellSpacing="30" CellPadding="50" OnPageIndexChanging="OnPageIndexChanging">
<Columns>
<asp:BoundField DataField="collection_id" HeaderText="Collection Id" ItemStyle-Width="30" ItemStyle-Height="35" />
<asp:BoundField DataField="customer_id" HeaderText="Customer Name" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_type" HeaderText="Collection Type" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_date" HeaderText="Collection Date" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_amt" HeaderText="Collection Amount" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_chqno" HeaderText="Collection Cheque Number" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_chdate" HeaderText="Collection Cheque Date" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_refno" HeaderText="Collection Ref Number" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_note" HeaderText="Collection Note" ItemStyle-Width="150" />
<asp:BoundField DataField="status" HeaderText="Status" ItemStyle-Width="150" />
<asp:BoundField DataField="updated_by" HeaderText="Updated By" ItemStyle-Width="150" />
<asp:BoundField DataField="updated_on" HeaderText="Updated On" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
protected void btnSearch_Click(object sender, EventArgs e)
{
string customerText = customerDetails.SelectedItem.Value;
string query = @"select * from app_collection_master where customer_id="+customerText;
using (DataTable dt = SMSDBHelperFE.ExecuteReaderDataTable(CommandType.Text, query, null))
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
现在我可以显示 Id 但如果 Id 我需要显示名称 如何实现 i.
在select查询中,加入存储客户名称的table。喜欢
select * from app_collection_master inner join customerTable on customerTable.customerId=app_collection_master.customer_id where app_collection_master.customer_id="+customerText;
然后在网格中绑定客户名称
<asp:BoundField DataField="customer_name" HeaderText="Customer Name" ItemStyle-Width="150" />
我有一个 GridView,其中我根据选定的客户名称显示网格,在网格中我有一个客户 ID 而不是那个客户 ID 我需要显示其值不同的客户名称 Table如何使用 asp.net 实现它。
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#2A3F54" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" Width="100%" Height="100%" CellSpacing="30" CellPadding="50" OnPageIndexChanging="OnPageIndexChanging">
<Columns>
<asp:BoundField DataField="collection_id" HeaderText="Collection Id" ItemStyle-Width="30" ItemStyle-Height="35" />
<asp:BoundField DataField="customer_id" HeaderText="Customer Name" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_type" HeaderText="Collection Type" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_date" HeaderText="Collection Date" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_amt" HeaderText="Collection Amount" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_chqno" HeaderText="Collection Cheque Number" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_chdate" HeaderText="Collection Cheque Date" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_refno" HeaderText="Collection Ref Number" ItemStyle-Width="150" />
<asp:BoundField DataField="collection_note" HeaderText="Collection Note" ItemStyle-Width="150" />
<asp:BoundField DataField="status" HeaderText="Status" ItemStyle-Width="150" />
<asp:BoundField DataField="updated_by" HeaderText="Updated By" ItemStyle-Width="150" />
<asp:BoundField DataField="updated_on" HeaderText="Updated On" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
protected void btnSearch_Click(object sender, EventArgs e)
{
string customerText = customerDetails.SelectedItem.Value;
string query = @"select * from app_collection_master where customer_id="+customerText;
using (DataTable dt = SMSDBHelperFE.ExecuteReaderDataTable(CommandType.Text, query, null))
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
现在我可以显示 Id 但如果 Id 我需要显示名称 如何实现 i.
在select查询中,加入存储客户名称的table。喜欢
select * from app_collection_master inner join customerTable on customerTable.customerId=app_collection_master.customer_id where app_collection_master.customer_id="+customerText;
然后在网格中绑定客户名称
<asp:BoundField DataField="customer_name" HeaderText="Customer Name" ItemStyle-Width="150" />