Display Names instead of Id in a GridView whose value is there in different table using asp.net

334 Views Asked by At

I have a gridView in which i have two foreign keys whose value is there in different table i am able to display only Id but i need to display its name based on its Id how to achieve it using 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="order_id" HeaderText="ORDER ID" ItemStyle-Width="30" ItemStyle-Height="35" />
             <asp:BoundField DataField="order_ref_no" HeaderText="ORDER REF NO" ItemStyle-Width="150" />
             <asp:BoundField DataField="order_date" HeaderText="ORDER DATE" ItemStyle-Width="150" />
             <asp:BoundField DataField="customer_id" HeaderText="CUSTOMER ID" ItemStyle-Width="150" />
             <asp:BoundField DataField="first_name" HeaderText="USER NAME" ItemStyle-Width="150" />                        
         </Columns>
   </asp:GridView>

my asp.net code

 string customerText= customerDetails.SelectedItem.Value;              

string queries = @"select * from app_order_master inner join app_user on app_user.user_id = app_order_master.user_id where app_order_master.user_id=" + customerText;;

   using (DataTable dt = SMSDBHelperFE.ExecuteReaderDataTable(CommandType.Text, queries, null))
        {

           GridView1.DataSource = dt;
           GridView1.DataBind();                    
        }

enter image description here

enter image description here

Now i am only able to join one id value (user name) using inner join but i need to display customer name instead of ID How to achieve it using asp.net

0

There are 0 best solutions below