Click here to Skip to main content
15,036,363 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a gridview and this gridview is bind to two database tables(Using Join). all column are template field.Normally this gridview show data as i want, but i also want to edit and add records using edit item template and footer template.
Because in the database their is foreign -primary key relation between two tables.
so i have used dropdownlist in for edit and add new records(template) to select id to foreign key column for one table.
I tried to bind these to dropdownlist using Row_DataBound() Event of gridview but it through exception at run time that object is not set to reference.

So please suggest me the other ways to bind dropdownlist with data from table in the edit and footer template of gridview.

thanks ]

\\\\
Balwant
Posted

1 solution

Do one thing add event of dropdownlist

XML
<asp:dropdownlist id="ddl1" runat="server" onload="dropdown1_load">

in codebehind
C#
protected void dropdown1_load(object sender,EventArgs e)
{
    SqlDataAdapter da = new SqlDataAdapter("select sno from student", cn);
    DataTable dt = new DataTable();
    da.Fill(dt);
    DropDownList ddl = (DropDownList)sender;
    ddl.DataSource = dt;
    ddl.DataTextField = "sno";
    ddl.DataValueField = "sno";
    ddl.DataBind();
}
   
v3
Comments
Ankur\m/ 2-May-11 1:02am
   
Surround code snippets with PRE tags (code block). It makes the code readable.
velmahesh 2-May-11 1:32am
   
Hi Balwant,

i think it will work..
Balwant.mnd 2-May-11 1:37am
   
no it is not working because dropdownlist does not found because it is in the gridview edit template.
i will also tried to find suitable solution for it
Balwant.mnd 2-May-11 2:00am
   
Thanks Now it is working!
thanks a lot
Balwant.

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