ListView EditItemTemplate

O

onseats.ky

I'm trying to get access controls in the EditItemTemplate of a list
view when the user edits an item. I need to set focus to a textbox in
this template after post back because the ListView is in a long
scrolling div. Without setting focus the user needs to scroll down the
div after postback to get to the item.

I've tried using listview.FindControl('tbxEdit') but this comes back
blank. Does anyone have any ideas?

thanks in advance.
 
J

jx.su.go

I'm trying to get access controls in the EditItemTemplate of a list
view when the user edits an item. I need to set focus to a textbox in
this template after post back because the ListView is in a long
scrolling div. Without setting focus the user needs to scroll down the
div after postback to get to the item.

I've tried using listview.FindControl('tbxEdit') but this comes back
blank. Does anyone have any ideas?

thanks in advance.

Debug it then you can find the reason!
 
J

jx.su.go

I'm trying to get access controls in the EditItemTemplate of a list
view when the user edits an item. I need to set focus to a textbox in
this template after post back because the ListView is in a long
scrolling div. Without setting focus the user needs to scroll down the
div after postback to get to the item.

I've tried using listview.FindControl('tbxEdit') but this comes back
blank. Does anyone have any ideas?

thanks in advance.

Debug it then you can find the reason!
 
O

onseats.ky

<asp:ListView ID="lvwTemplates" runat="server"
InsertItemPosition="FirstItem"
OnItemCommand="lvwTemplates_OnItemCommand"
OnItemCanceling="lvwTemplates_OnItemCanceling"
OnItemEditing="lvwTemplates_OnItemEditing"
OnItemInserted="lvwTemplates_OnItemInserted"
OnItemInserting="lvwTemplates_OnItemInserting"
OnItemDeleting="lvwTemplates_OnItemDeleting"
OnItemUpdating="lvwTemplates_OnItemUpdating"
<LayoutTemplate>
<div>
<table>
<tr>
<td><asp:Button ID="btnNewTemplate"
runat="server" Text="New Template" OnClick="btnNewTemplate"
CausesValidation="false" /></td>
<td><asp:Button ID="btnBulkEdit"
runat="server" Text="Bulk Edit" OnClick="btnBulkEdit"
CausesValidation="false" /></td>
</tr>
</table>

<div id="elementViewer">
<asp:placeHolder ID="itemContainer"
runat="server" />
</div>
</div>
</LayoutTemplate>
<ItemTemplate>
<table width="400px">
<tr>
<td width="325px">
<asp:Label ID="lblTemplateID" runat="server"
Text="<%#((Bullsh1tTemplate)Container.DataItem).TemplateID %>"
Visible="false" />
<asp:Literal ID="ltrTemplate" runat="server"
Text="<%#((Bullsh1tTemplate)Container.DataItem).TemplateBody %>" />
</td>
<td><asp:Button ID="btnEdit" runat="server"
CommandName="edit" Text="Edit"/></td>
<td><asp:Button ID="btnDelete" runat="server"
CommandName="delete" Text="Delete" /></td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<gaia:Label ID="lblTemplateID" runat="server" Text="<
%#((Bullsh1tTemplate)Container.DataItem).TemplateID %>"
Visible="false" />
<table width="400px">
<tr>
<td width="325px">
<asp:TextBox ID="tbxTemplate" runat="server"
Text="<%#((Bullsh1tTemplate)Container.DataItem).TemplateBody %>" />
<asp:RequiredFieldValidator ID="rfvTemplate"
ControlToValidate="tbxTemplate" Text="required" runat="server"
Display="Dynamic" />
</td>
<td><asp:Button ID="btnUpdate" runat="server"
CommandName="update" Text="Update" /></td>
<td><asp:Button ID="btnCancel" runat="server"
CommandName="cancel" Text="Cancel" CausesValidation="false" /></td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table width="250px">
<tr>
<asp:RequiredFieldValidator ID="rfvTemplate"
ControlToValidate="tbxTemplate" Text="required" runat="server"
Display="Dynamic" />
</td>
<td><asp:Button ID="btnInsert" runat="server"
CommandName="insert" Text="Save" /></td>
<td><asp:Button ID="btnCancel" runat="server"
CommandName="cancel" Text="Cancel" CausesValidation="false" /></td>
</tr>
</table>
</InsertItemTemplate>
<EmptyDataTemplate>
This rule is currently empty
</EmptyDataTemplate>
</asp:ListView>


c# code

protected void lvwTemplates_OnItemEditing(object sender,
ListViewEditEventArgs e)
{
ListView listView = (ListView)sender;
TextBox tbx =
listView.FindControl("tbxTemplate")
}

In the sample above tbx gets set to null
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top