TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Najjaf Shuja
NA
3
5.7k
Can't access gridview row in dropdown selected index changed
Jun 4 2014 7:40 AM
Hi, I am developing a web application using asp.net, c#.
I have simple gridview control having dropdown in it. in gridview rowdatabound event, i call dropdown selected index changed event. there i get gridview row but exception comes.
My code is below.
protected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
table1 obj = e.Row.DataItem as table1;
DropDownList ddldepartment = e.Row.FindControl("ddldepartment ") as DropDownList;
/// Bind Dropdownlists
#region DDL Department
ddldepartment.DataSource = new x_SystmController().GetAllDepartments();
ddldepartment.DataTextField = "Title";
ddldepartment.DataValueField = "PK_id";
ddldepartment.DataBind();
ddldepartment.Items.Insert(0, new ListItem("--- Select ---", "0"));
#endregion
if (obj.fk_department_id > 0)
{
ddldepartment.SelectedValue = obj.fk_department_id.ToString();
ddlSystem_SelectedIndexChanged(this, new EventArgs()); // It will call the index changed event of ddl written below
}
}
protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gvr = (GridViewRow)(((Control)sender).NamingContainer); // Here i get null value
Label lbName = gvr.FindControl("lbName") as Label; // Here exception comes object reference is not set to the instance
}
Please help....
Thanks in advance..!!!!
Reply
Answers (
2
)
How To Add Site Map in Existing Mvc Application
how 2 reterive dta using drop down