Hi,
I have this part in the Gridview.
<asp:TemplateField HeaderText="Student">
<ItemTemplate>
<asp:DropDownList ID="ddl" OnSelectedIndexChanged="ddl_IndexChanged" runat="server">
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl2" OnSelectedIndexChanged="ddl_IndexChanged" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddl3" OnSelectedIndexChanged="ddl_IndexChanged" runat="server">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
I do touch this method for handling ddl2 & ddl3 as well.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("ddl");
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select stu_id,rtrim(ltrim(cast(stu_id as varchar)))+' '+stu_name stu_name from Student where stu_id>=12 order by 1";
ddl.DataSource = GetData(cmd);
ddl.DataTextField = "stu_name";
ddl.DataValueField = "stu_id";
ddl.DataBind();
DropDownList ddl2 = (DropDownList)e.Row.FindControl("ddl2");
cmd.CommandText = "select stu_id,rtrim(ltrim(cast(stu_id as varchar)))+' '+stu_name stu_name from Student where stu_id>=12 order by 1";
ddl2.DataSource = GetData(cmd);
ddl2.DataTextField = "stu_name";
ddl2.DataValueField = "stu_id";
ddl2.DataBind();
DropDownList ddl3 = (DropDownList)e.Row.FindControl("ddl3");
cmd.CommandText = "select stu_id,rtrim(ltrim(cast(stu_id as varchar)))+' '+stu_name stu_name from Student where stu_id>=12 order by 1";
ddl3.DataSource = GetData(cmd);
ddl3.DataTextField = "stu_name";
ddl3.DataValueField = "stu_id";
ddl3.DataBind();
}
}
After the change, when it is to bind data, I get this Exception message. Why?
Object reference not set to an instance of an object.
Many Thanks & Best Regards,
HuaMin