Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Using Gridview with templete Field of DropDown
at RowdtatBound I Use a function which returns datatable and I bind it with
template column of DropDown.

After that when i try to select the value in templete Field of DropDown
It gives me error of

"Object reference not set to an instance of an object."

although the data which i try to set in dropdown its present becuase first i
populate the dropdown and then set the value by using

SQL
gvReading_ddlgv.Items.FindByValue(strLastReading).Selected = True


Whts the problem Need Help !!!
Posted
Comments
NMehta83 18-Feb-11 7:04am    
in each postback event you need to first bind the data to the grid and then you can select your item in the dropdown. Can you share your code of aspx page and aspx.cs page?

1 solution

simply,

manually write dropdown selectindexchanged event in sourcefile and .cs file and set autopostback=true.then in selectedindexchanged event use sender object to retreive combobox selectedindex and text and use dropdownlist clientid to get selected row like

DropDownList ddl = (DropDownList)sender;
string s = ddl.ClientID;//use substring to retreive rowindex
if (ddl.SelectedItem.Text == "Your selected text"){dropdown1.Items.FindByText("Your text"].ToString()).Selected=true;}
 
Share this answer
 

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