Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hi Expert,

I am uday Satardekar,

In my edit_event.aspx page ,there is one Listview(listvwEventResult).

I took one Textbox(txtEditEventName) in EditTemplate in Listbox.

ex
<td>
                    <asp:TextBox ID="txtEditEventName" runat="server" 
                        Text='<%# Bind("event_name") %>' />
                </td>



when i am finding above Textbox(txtEditEventName) OnItemUpdating
working fine.
ex...

ListViewItem item = listvwEventResult.Items[e.ItemIndex];
            Int64 eventID = Int64.Parse(listvwEventResult.DataKeys[e.ItemIndex].Value.ToString());
            TextBox eventName = (TextBox)item.FindControl("txtEditEventName");
            string nm = eventName.Text;



But when i am finding same control onItemDataBound or ItemCreated it shows null reference.

This problem is arrived only for controls in editTemplate

ex
 ListViewDataItem item = (ListViewDataItem)e.Item;

            TextBox txtEvName = (TextBox)e.Item.FindControl("txtEditEventName");
string nm = eventName.Text;


Here txtEvName shows null value.

And this problem is arrived only for EditTemplate

what i am missing Here?

Please help me how to find control on itemdatabound event.

Thanksss in advance.
Posted
Updated 27-Oct-11 0:41am
v4

1 solution

I solve this problem.

I add following code onItemDataBound event

if (listvwEventResult.EditIndex > -1)
       {
           ListViewDataItem item = (ListViewDataItem)e.Item;


           if (item.DisplayIndex == listvwEventResult.EditIndex)
           {
               try
               {

                   DropDownList listEditCountry = (DropDownList)e.Item.FindControl("lstEditCountry");

                   DropDownList listEditCategory = (DropDownList)e.Item.FindControl("lstEditCategory");



                   string queryStrCountry = "SELECT country_id,country_name FROM  crm_countries";
                   string queryStrCategory = "SELECT cat_id,category FROM  crm_category";

                   ClassFillDropDown fillCountry = new ClassFillDropDown();
                   ClassFillDropDown fillCat = new ClassFillDropDown();
                   fillCountry.FillDropdown(queryStrCountry, "country_id", "country_name", listEditCountry);
                   fillCat.FillDropdown(queryStrCategory, "cat_id", "category", listEditCategory);



                   DataRowView rowView = (DataRowView)item.DataItem;
                   String countryName = rowView["country_id"].ToString();
                   String Category = rowView["category"].ToString();
                   DropDownList listCountry = (DropDownList)item.FindControl("lstEditCountry");
                   DropDownList listCat = (DropDownList)item.FindControl("lstEditCategory");
                   ListItem item1 = listCountry.Items.FindByValue(countryName);
                   listCountry.SelectedIndex = listCountry.Items.IndexOf(item1);

                   ListItem item2 = listCat.Items.FindByText(Category);
                   listCat.SelectedIndex = listCat.Items.IndexOf(item2);



               }
               catch (Exception Ex)
               {

               }


           }
       }
 
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