ASP.Net GridView Edit ItemTemplate Mode

by top54u.com 09 Jul, 2008
Spotlight.....

GridView Data Control of ASP.Net 2.0 supports Edit mode and Data Update command. GridView Control consists of TemplateField column that can show the multiple data items. TemplateField of GridView control provides ItemTemplate and EditItemTemplate that enables you to change the GridView mode to edit or read only mode. RowEditing Event hides the ItemTemplate and shows the EditItemTemplate. You can place the DataBinder code in the ItemTemplate of TemplateField to display the read only view of GridView Data retrieved from the Database. To display the GridView Edit mode, you can place the textboxes inside the EditItemTemplate and assign the value to Text property of textboxes using DataBinder method to display the old database value in edit mode.

 

 

HTML Source Code for ASP.Net GridView Edit ItemTemplate Mode

 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="2" GridLines="None" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" Width="500px" DataKeyNames="categoryId" BorderStyle="None" ShowHeader="False" CellSpacing="2">

<Columns>

<asp:TemplateField>

<ItemTemplate>

<div class="outer">

<div class="inner">

<div class="innerTitle">

<b>Category:</b>

</div>

<div class="innerContent">

<%# DataBinder.Eval(Container.DataItem,"categoryName") %>

</div>

</div>

<div class="clear"></div>

<div class="inner">

<div class="innerTitle">

<b>Description:</b>

</div>

<div class="innerContent">

<%# DataBinder.Eval(Container.DataItem,"description") %>

</div>

</div>

<div class="clear"></div>

</div>

</ItemTemplate>

 

<EditItemTemplate>

<div class="outer">

<div class="inner">

<div class="innerTitle">

<b>Category:</b>

</div>

<div class="innerContent">

<asp:TextBox ID="txtCategoryName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"categoryName") %>' ></asp:TextBox>

</div>

</div>

<div class="clear"></div>

<div class="inner">

<div class="innerTitle">

<b>Description:</b>

</div>

<div class="innerContent">

<asp:TextBox ID="txtDescription" runat="server" Width="300px" Text='<%# DataBinder.Eval(Container.DataItem,"description") %>' ></asp:TextBox>

</div>

</div>

<div class="clear"></div>

</div>

</EditItemTemplate>

 

</asp:TemplateField>

 

<asp:CommandField ShowEditButton="True">

<HeaderStyle HorizontalAlign="Left" />

</asp:CommandField>

</Columns>

</asp:GridView>

 

In the next article you can learn C# code to handle the ASP.Net GridView edit and cancel events.

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:49:38 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....