How to populate dropdownlist within the grid?
-
hello everyone, I need your help once again. Had a problem in populating dropdownlist within the grid. Anyone pls help.. <EditItemTemplate> <asp:DropDownList CssClass="CellValue" ID="ddlCategories" Runat="server" Width="100%"></asp:DropDownList> </EditItemTemplate> code behind:: private void gvDisclosures_ItemDataBound(object sender, EventArgs e) { DropDownList list = (DropDownList) e.Item.FindControl("ddlCategories"); // Set the text and value properties // for the dropdown list to appropriate columns in the // data source list.DataTextField = "fcCatCode"; list.DataValueField = "fcCatCode"; list.DataSource = m_uf.loadCategory(); list.DataBind(); } when i click the edit button.... i always encounter an error on the behind code: can someone help me on this one.. your help is highly appreciated tnx. :laugh: start a new beginning in every ending; thats what life for......
-
hello everyone, I need your help once again. Had a problem in populating dropdownlist within the grid. Anyone pls help.. <EditItemTemplate> <asp:DropDownList CssClass="CellValue" ID="ddlCategories" Runat="server" Width="100%"></asp:DropDownList> </EditItemTemplate> code behind:: private void gvDisclosures_ItemDataBound(object sender, EventArgs e) { DropDownList list = (DropDownList) e.Item.FindControl("ddlCategories"); // Set the text and value properties // for the dropdown list to appropriate columns in the // data source list.DataTextField = "fcCatCode"; list.DataValueField = "fcCatCode"; list.DataSource = m_uf.loadCategory(); list.DataBind(); } when i click the edit button.... i always encounter an error on the behind code: can someone help me on this one.. your help is highly appreciated tnx. :laugh: start a new beginning in every ending; thats what life for......
Can you post here error and on which line ?
Parwej Ahamad R & D: REST services with WCF
-
hello everyone, I need your help once again. Had a problem in populating dropdownlist within the grid. Anyone pls help.. <EditItemTemplate> <asp:DropDownList CssClass="CellValue" ID="ddlCategories" Runat="server" Width="100%"></asp:DropDownList> </EditItemTemplate> code behind:: private void gvDisclosures_ItemDataBound(object sender, EventArgs e) { DropDownList list = (DropDownList) e.Item.FindControl("ddlCategories"); // Set the text and value properties // for the dropdown list to appropriate columns in the // data source list.DataTextField = "fcCatCode"; list.DataValueField = "fcCatCode"; list.DataSource = m_uf.loadCategory(); list.DataBind(); } when i click the edit button.... i always encounter an error on the behind code: can someone help me on this one.. your help is highly appreciated tnx. :laugh: start a new beginning in every ending; thats what life for......
moomoooomoo wrote:
DropDownList list = (DropDownList) e.Item.FindControl("ddlCategories");
Whatever the error is, you should never call find control, do the cast instead of using 'as' and then just use it right away. Write defensive code, that will not blow up if the FindControl call fails. Try to write a site that won't ever blow up, even if it doesn't work as you hope for some reason. I am suspecting that is what's happening, b/c that's all I can see that could go wrong.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )