Click here to Skip to main content
15,999,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display name in in grid view ..i have drop down in my form but when i select the item from drop down the id is inserted into database but when i am loading the grid the same id is displayed in the grid ..how to get the name of that particular id in my grid view ...i am new to this field please help me

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
onrowediting="GridView1_RowEditing" onsorting="GridView1_Sorting"
DataKeyNames ="pk_crm_leadid" Width="722px" AllowPaging="True"
BorderStyle="Ridge" CssClass="TDClass" GridLines="Horizontal"
onpageindexchanging="GridView1_PageIndexChanging" CellPadding="2">
<columns> <asp:TemplateField HeaderText="pk_crm_leadid" Visible = "false">
<itemtemplate>
<asp:Label ID="pk_crm_leadid" runat="server" Text='<%# Bind("pk_crm_leadid") %>'>



<asp:TemplateField HeaderText="Customer Name" >
<itemtemplate>
<asp:Label ID="txtpartyname" runat="server" Text='<%# Bind("crm_customername") %>'>



<asp:TemplateField HeaderText="Address " >
<itemtemplate>
<asp:Label ID="txtadd1" runat="server" Text='<%# Bind("crm_address") %>'>



<asp:TemplateField HeaderText="Telephone " >
<itemtemplate>
<asp:Label ID="txttel" runat="server" Text='<%# Bind("crm_telephone") %>'>



<asp:TemplateField HeaderText="Fax No" >
<itemtemplate>
<asp:Label ID="txtfaxno" runat="server" Text='<%# Bind("crm_faxno") %>'>



<asp:TemplateField HeaderText="Mobile" >
<itemtemplate>
<asp:Label ID="txtmbl" runat="server" Text='<%# Bind("crm_mobile") %>'>



<asp:TemplateField HeaderText="Email Id" >
<itemtemplate>
<asp:Label ID="txtemailid" runat="server" Text='<%# Bind("crm_emailid") %>'>



<asp:TemplateField HeaderText="Website" >
<itemtemplate>
<asp:Label ID="txtwebsite" runat="server" Text='<%# Bind("crm_website") %>'>



<asp:TemplateField HeaderText="Contact Name" >
<itemtemplate>
<asp:Label ID="txtcontactname" runat="server" Text='<%# Bind("crm_contactname") %>'>



<asp:TemplateField HeaderText="Assign To" >
<itemtemplate>
<asp:Label ID="drdnlist_emp" runat="server" Text='<%# Bind("fk_crm_assignto") %>'>




<asp:TemplateField HeaderText="Edit">
<itemtemplate>
<asp:LinkButton ID="lnkbtnedit" runat="server" CommandName="edit">Edit

<%--<edititemtemplate>
<asp:LinkButton ID="lnkbtncancel" runat="server" CommandName="Cancel">Cancel
<asp:LinkButton ID="lnkbtnupdate" runat="server" CommandName="Update">Update
--%>





this is my grid view and this is the code in which i want to bind empname (<asp:Label ID="drdnlist_emp" runat="server" Text='<%# Bind("fk_crm_assignto") %>'>) but when i am joining the query am getting error

this is the select query i am using to fill grid SELECT a.pk_crm_leadid,a.crm_customername ,a.crm_address,a.crm_telephone,a.crm_faxno,a.crm_mobile,a.crm_emailid,a.crm_website,a.crm_contactname,a.fk_crm_assignto,b.empname FROM crm_lead a,employee b where b.empno = a.fk_crm_assignto
Posted
Updated 21-Jan-14 21:45pm
v2
Comments
Rockstar_ 22-Jan-14 1:22am    
May b u r storing the drop down values in other table right?
U need to join another table where ur drop down text and values are stored.
vivek0041 22-Jan-14 2:20am    
yes i am binding the drop down from another table and then selecting the index from drop down but when i joined the table still error is coming in grid view DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'empname'...this empname is column of employee table and i have binded this in drop down ..and thanks for replying
Tom Marvolo Riddle 22-Jan-14 2:42am    
Post your code snippet.Use Improve question to edit
Tom Marvolo Riddle 22-Jan-14 4:45am    
Please include what error you're getting.If error is in SQL then you have to change the query
vivek0041 22-Jan-14 4:59am    
System.Data.DataRowView' does not contain a property with the name 'empname'..this is the error when i am changing <asp:Label ID="drdnlist_emp" runat="server" Text='<%# Bind("fk_crm_assignto") %>'> to <asp:Label ID="drdnlist_emp" runat="server" Text='<%# Bind("empname") %>'>

The select query doesn't have a column empname but you are trying to bind it with gridview

For eg;
SQL
select column1,column2 from tablename

if you have query like this then mark up should be like this:
ASP.NET
<asp:Label ID="label1" runat="server" Text='<%#Eval("column1") %>'></asp:Label>
<asp:Label ID="label2" runat="server" Text='<%#Eval("column2") %>'></asp:Label>
 
Share this answer
 
v3
it may help you:

<asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
<headertemplate>

SNo
Mobile No.
User
Department
Assign Date
Short No.
Credit Limit
City
Action

<itemtemplate>
<%# Eval("SNo")%>
<%# Eval("MobileNo")%>
<%# Eval("Name")%>
<%# Eval("Department")%>
<%# Eval("AssignDate")%>
<%# Eval("ShortNo")%>
<%# Eval("CreditLimit")%>
<%# Eval("City")%>

<%----%>Del

 

<%-- --%>
Edit


<footertemplate>


 
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