Simple DataGrid issue: driving me nuts:

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I'm following the example in this site:

http://aspnet.4guysfromrolla.com/articles/071002-1.2.aspx


It uses "BoundColumn" and "Edit/Update/Cancel" that goes with each row...Click on "Edit", and you'll get "Update/Cancel" buttons and the fields change to text fields for editing

But

I want to use "TemplateColumn" with "Edit/Update/cancel" button next to each row...

However, when I have "TemplateColumn", and click on "Edit", i DO get the "update/cancel" buttons but the field DOES NOT change to a text field for me to change the text in it..

So, I cant use "TemplateColumn" with "Edit/Update/Cancel"??
 
I tried to add <EditItemTemplate> but it didnt like it..got a redline under it saying cannot find the member <EditItemTemplate> ...

This is what I have:

-----

<asp:datagrid id="dgViewDetail" style="Z-INDEX: 101; LEFT: 230px; POSITION: absolute; TOP: 148px" runat="server" AutoGenerateColumns="False" Width="697px" Height="200px" OnEditCommand="Site_Edit">
<Columns >
<asp:TemplateColumn >
<ItemTemplate >
<table border="0">
<tr>
<td align="right"><b>Site Name:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "cmp_name1") %></td>
</tr>
<tr>
<td align="right"><b>Site Addr1:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "cmp_addr1") %></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:datagrid>
 
<asp:edititemtemplate><%# DataBinder.Eval(Container.DataItem, "cmp_name1") %></edititemtemplate></td>

But then in design view, the grid has "error creating grid" msg

Also Tried:

<asp:TemplateColumn>
<asp:edititemtemplate>
<table border="0">
<tr>
<td align="right"><b>Site Name:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "cmp_name1") %></td>
</tr>
<tr>
<td align="right"><b>Site Addr1:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "cmp_addr1") %></td>
</tr>
</table>
</edititemtemplate>
</asp:TemplateColumn>
 
I believe its..
Code:
<asp:TemplateColumn>

  <ItemTemplate>
     <%# Container.DataItem("Name")  %>
  </ItemTemplate>
  <EditItemTemplate>
     <asp:Textbox id="txtName" runat="server" Text='<%# Container.DataItem("Name")  %>'><asp:Textbox>
  </EditItemTemplate>
</asp:TemplateColumn>

not <asp:EdititemTemplate
 
Thanks...getting close..i dont want to have a row with several columns... i want to have a column and then the fields arragned in rows...

This is what I have now: it displays fine
<Columns>
<asp:TemplateColumn HeaderText="FAQ Information">
<ItemTemplate>
<table border="0">
<tr>
<td align="right"><b>Site Name:</b></td>
<td><EditItemTemplate>
<asp:TextBox id="cmp_name1" Width="200px" MaxLength="20" Text='<%# Container.DataItem("cmp_name1")%>' Runat="server" Columns="6">
</asp:TextBox>
</EditItemTemplate></td>
</tr>
<tr>
<td align="right"><b>Site Addr1:</b></td>
<td><EditItemTemplate>
<asp:TextBox id="Textbox1" Width="200px" MaxLength="20" Text='<%# Container.DataItem("cmp_addr1")%>' Runat="server" Columns="6">
</asp:TextBox>
</EditItemTemplate></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

But under <EditItemTemplate>, I get a red line with the msg: The active schema does not support the elemenet <EditItemTemplate>

Why??
 
You cannot have a EditItemTemplate nested under an ItemTemplate. Look at my example. The EditItemTemplate is the same as the ItemTemplate, except that instead of the normal values, i place the values into editable input fields, like textboxes, dropdownlists, etc...So...when you enter the Edit mode, it displays the EditItemTemplate instead.
 
ah..thanks so much for sticking with me about this issue...

one more thing:

How can I have it with HTML code? can I even have it with HTML code?? i want my columns to be in ONE coulmn arragned in rows..
 
thanks

This is what I've been trying to do.finally got it...thanks for all your help...

<Columns>
<asp:TemplateColumn HeaderText="Site Information">
<ItemTemplate>
<table border="0">
<tr>
<td align="left"><b>Site Name:</b></td>
<td>
<%# Container.DataItem("cmp_name1") %>
</td>
</tr>
<tr>
<td align="right"><b>Site Address:</b></td>
<td>
<%# Container.DataItem("cmp_addr1") %>
</td>
</tr>
</table>
</ItemTemplate>
<EDITITEMTEMPLATE>
<table border="0">
<tr>
<td align="left"><b>Site Name:</b></td>
<td>
<asp:TextBox id="cmp_name1" Width="200px" Runat="server" Text='<%# Container.DataItem("cmp_name1")%>' MaxLength="20">
</asp:TextBox>
</td>
</tr>
<tr>
<td align="right"><b>Site Address:</b></td>
<td>
<asp:TextBox id="cmp_addr1" Width="200px" Runat="server" Text='<%# Container.DataItem("cmp_addr1")%>' MaxLength="20">
</asp:TextBox>
</td>
</tr>
</table>
</EDITITEMTEMPLATE>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">
<HeaderStyle Width="50px"></HeaderStyle>
</asp:EditCommandColumn>
</Columns>
 
Back
Top