Last post Oct 15, 2009 05:31 PM by MetalAsp.Net
Oct 15, 2009 03:39 PM|mychucky|LINK
Will somone show me how to access the controls such as Lable, TextBox, or HiddenField controls inside a LstView ItemTemplate? I want to insert this information into a SQL Server database but I couldn't figure out a way to get those information from C# code
Oct 15, 2009 03:53 PM|MetalAsp.Net|LINK
The basic idea is that you need to use FindControl on a specify Item in the listview. So you need to find the item in question, maybe via a datakeynames key, or via an event that potentially exposes e.Item as a property. Then you do FindControl on the
item and cast it to the control type. You'll then have access to the control's properties.
Oct 15, 2009 04:13 PM|mychucky|LINK
Yes that's the basic idea and I know how to do that for EditItemTemplate, InsertItemTemplate but now I need to access the ItemTemplate. To access the InsertItemTemplate I use the PrePrender method and to access the EditItemTemplate, I had to use the OnPreRender
method of the control itself; however, when I'm trying to access the ItemTemplate, there are just more than one item inside the ItemTemplate or AlternatingItemTemplate. How do I find the right item that I want and how do I find it? What method or what property
do I use to get inside the ItemTemplate and AlternatingItemTemplate. That's where I get stuck.
Oct 15, 2009 05:27 PM|Ahmish|LINK
Use this event to access the controls from the ItemTemplate
protected void DataList_ItemCommand(object source, DataListCommandEventArgs e)
TextBox txt= (e.Item.FindControl("TextBox1") as TextBox).Text
Oct 15, 2009 05:31 PM|MetalAsp.Net|LINK
You could handle the ItemDataBound event, and in there check e.Item.ItemType == ListViewItemType.DataItem then do e.Item.FindControl(etc.).