Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I take one gridview with linkbutton ineach row.
After clicking on link button edit it sets value to textbox properly but at the Dropdown list it give an error 'Object reference not set to an instance of an object'
My code is as follow
if (e.CommandName.Equals("EditRecord"))
               {
                   GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                   tbxCode.Text = row.Cells[1].Text;
                   tbxName.Text = row.Cells[2].Text;

                   ddlSection.SelectedItem.Text= row.Cells[3].Text;
                   tbxdesc.Text = row.Cells[4].Text;

                   MultiView1.SetActiveView(ViewAdd);
               }

Can anybody please help me....
Thank you...
Posted
Comments
BIBASWAN 4-Nov-15 7:06am    
first check what value is in row.Cells[3].Text and then check that your Dropdown list have that same value or not.
John C Rayan 4-Nov-15 7:21am    
ddlSection.SelectedItem is read only property. You cannot assign a value to this property.
asplover1 5-Nov-15 0:36am    
But On same page it works properly. In this case the view is changed to view2 and my dropdownlist is on view2 and grid view on view1.
John C Rayan 5-Nov-15 4:22am    
When you say it works on the same page , can you show us the code for that. I am surprised that you could assign a value to a read only property.
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selecteditem(v=vs.110).aspx
asplover1 6-Nov-15 3:41am    
if (e.CommandName.Equals("EditRecord")) //onclick edit link button of grigview
{
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);


tbcPrtCode.Text = row.Cells[1].Text;;
tbxPrtNm.Text = row.Cells[2].Text;;
ddlsection.SelectedItem.Text = row.Cells[3].Text;

}

This is the code which executed properly.
But here the case is the gridview and ddl are on same page.

Have you checked the value of row.Cells[3].Text??
 
Share this answer
 
Comments
asplover1 5-Nov-15 0:34am    
Yes I check that. Its right. But give an error that object reference is not set to an instance of an object
Dear please fistly fill your drop down then set the dropdown value. it is giving error because of dropdown list is null
 
Share this answer
 
Comments
asplover1 17-Nov-15 4:02am    
Thak you. I got my problem

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