Dropdown in Gridview
-
Hi, I have a gridview which contain dropdownlist in every row. And there is a Save button in that page. I want to save the dropdownlist's value on clicking on the save button. But I am getting an error "Object reference not set to an instance of an object". Please look at the code I am using: foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls) { DropDownList ddlval = new DropDownList(); ddlval = (DropDownList)rec.FindControl("ddlvalidation"); string str = ddlval.SelectedItem.Text; }
Thanks & Regards Mishra
-
Hi, I have a gridview which contain dropdownlist in every row. And there is a Save button in that page. I want to save the dropdownlist's value on clicking on the save button. But I am getting an error "Object reference not set to an instance of an object". Please look at the code I am using: foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls) { DropDownList ddlval = new DropDownList(); ddlval = (DropDownList)rec.FindControl("ddlvalidation"); string str = ddlval.SelectedItem.Text; }
Thanks & Regards Mishra
Ballita wrote:
ddlval = (DropDownList)rec.FindControl("ddlvalidation");
have you checked that above line find the dropwdownlist or return Null value? best regard pAthAn
please don't forget to vote on the post that helped you.
-
Ballita wrote:
ddlval = (DropDownList)rec.FindControl("ddlvalidation");
have you checked that above line find the dropwdownlist or return Null value? best regard pAthAn
please don't forget to vote on the post that helped you.
-
Ballita wrote:
foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls)
try this and check out again
foreach(GridViewRow rec in this.gvsqldesc.Rows)
BesT regaRD pathanplease don't forget to vote on the post that helped you.
-
Ballita wrote:
foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls)
try this and check out again
foreach(GridViewRow rec in this.gvsqldesc.Rows)
BesT regaRD pathanplease don't forget to vote on the post that helped you.
-
Hey, I have tried this one also. It is not returning null but it is not fetching the values.
Thanks & Regards Mishra
Ballita wrote:
ddlval.SelectedItem.Text;
ddlval.SelectedValue;
bEst Regard pAthaN
please don't forget to vote on the post that helped you.
-
Hi, I have a gridview which contain dropdownlist in every row. And there is a Save button in that page. I want to save the dropdownlist's value on clicking on the save button. But I am getting an error "Object reference not set to an instance of an object". Please look at the code I am using: foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls) { DropDownList ddlval = new DropDownList(); ddlval = (DropDownList)rec.FindControl("ddlvalidation"); string str = ddlval.SelectedItem.Text; }
Thanks & Regards Mishra
Try something like this: foreach (GridViewRow rec in this.gvsqldesc.Rows) { string str = (DropDownList)rec.FindControl("ddlvalidation").SelectedItem.Text; } Here am assuming that the name of you gridview is 'gvsqldesc'. All the Best.