通过id的ListView EditTemplate FindControl显示对itemDataBound或itemcreated事件的空引用. [英] ListView EditTemplate FindControl by id shows null reference on itemDataBound or itemcreated event .

查看:88
本文介绍了通过id的ListView EditTemplate FindControl显示对itemDataBound或itemcreated事件的空引用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家,

我今天是Satardekar,

在我的edit_event.aspx页面上,有一个 Listview (listvwEventResult).

我在列表框的EditTemplate中使用了一个Textbox(txtEditEventName).


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>




当我在上方找到Textbox( txtEditEventName ) OnItemUpdating
工作正常.
例如...




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;




但是当我在onItemDataBound或ItemCreated中找到相同的控件时,它显示为空引用.

仅对于 editTemplate
中的控件才出现此问题




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;



txtEvName此处显示空值.

而且此问题仅针对 EditTemplate
出现
我在这里想念的是什么?

请帮助我如何找到对 itemdatabound 事件的控制.

提前致谢.



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.

推荐答案

我解决了这个问题.

我添加以下代码onItemDataBound事件

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)
               {

               }


           }
       }


这篇关于通过id的ListView EditTemplate FindControl显示对itemDataBound或itemcreated事件的空引用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆