Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Put your <code>EditPanel</code> in a EditItemTemplate and use <code>Commands</code> , you are not using this control the way it was designed to be used:</p> <p><a href="http://msdn.microsoft.com/en-us/library/90xwe9s3%28v=VS.80%29.aspx" rel="nofollow">How to: Allow Users to Edit Items in DataList Web Server Controls</a> </p> <p><strong>Markup:</strong></p> <pre><code>&lt;asp:SqlDataSource ID="AllLettersDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ORMSTestConnectionString %&gt;" SelectCommand="SELECT * FROM [Letters] WHERE ([id] = @id)"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="HiddenLetterID" DefaultValue="1" Name="id" PropertyName="Value" Type="Int32" /&gt; &lt;/SelectParameters&gt; &lt;!--change this --&gt; UpdateCommand="UPDATE [Categories] SET [CategoryName] = @CategoryName, [Description] = @Description WHERE [CategoryID] = @original_CategoryID"&gt; &lt;UpdateParameters&gt; &lt;asp:Parameter Name="CategoryName" Type="String" /&gt; &lt;asp:Parameter Name="Description" Type="String" /&gt; &lt;asp:Parameter Name="original_CategoryID" Type="Int32" /&gt; &lt;/UpdateParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:DataList ID="LettersDataList" runat="server" DataSourceID="AllLettersDataSource" OnEditCommand="LettersDataList_EditCommand" OnCancelCommand="LettersDataList_CancelCommand" OnUpdateCommand="LettersDataList_UpdateCommand"&gt; &lt;ItemTemplate&gt; &lt;asp:Panel ID="ViewPanel" runat="server"&gt; &lt;h2&gt; Data1:&lt;/h2&gt; &lt;asp:Label ID="data1Label" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="100px" Text='&lt;%# Eval("data1") %&gt;' Width="500px" /&gt; &lt;h2&gt; data2:&lt;/h2&gt; &lt;asp:Label ID="data2Label" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="100px" Text='&lt;%# Eval("data2") %&gt;' Width="500px" /&gt; &lt;h2&gt; data3:&lt;/h2&gt; &lt;asp:Label ID="data3Label" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="100px" Text='&lt;%# Eval("data3") %&gt;' Width="500px" /&gt; &lt;/asp:Panel&gt; &lt;asp:Button ID="EditButton" runat="server" CommandName="edit" Text="Edit" /&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:Panel ID="EditPanel" runat="server"&gt; &lt;h2&gt; data1:&lt;/h2&gt; &lt;asp:TextBox ID="data1TextBox" runat="server" Height="100px" Text='&lt;%# Eval("data1", "{0}") %&gt;' TextMode="MultiLine" Width="500px"&gt;&lt;/asp:TextBox&gt; &lt;h2&gt; data2:&lt;/h2&gt; &lt;asp:TextBox ID="data2TextBox" runat="server" Height="100px" Text='&lt;%# Eval("data2", "{0}") %&gt;' TextMode="MultiLine" Width="500px"&gt;&lt;/asp:TextBox&gt; &lt;h2&gt; data3:&lt;/h2&gt; &lt;asp:TextBox ID="data3TextBox" runat="server" Height="100px" Text='&lt;%# Eval("data3", "{0}") %&gt;' TextMode="MultiLine" Width="500px"&gt;&lt;/asp:TextBox&gt; &lt;/asp:Panel&gt; &lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="update"&gt; Save &lt;/asp:LinkButton&gt; &amp;nbsp; &lt;asp:Button ID="CancelButton" runat="server" CommandName="cancel" Text="Cancel" Visible="False" /&gt; &lt;/EditItemTemplate&gt; &lt;/asp:DataList&gt; </code></pre> <p><strong>Code-behind:</strong></p> <pre><code> protected void LettersDataList_EditCommand(object source, DataListCommandEventArgs e) { LettersDataList.EditItemIndex = e.Item.ItemIndex; LettersDataList.DataBind(); } protected void LettersDataList_CancelCommand(object source, DataListCommandEventArgs e) { LettersDataList.EditItemIndex = -1; LettersDataList.DataBind(); } protected void LettersDataList_UpdateCommand(object source, DataListCommandEventArgs e) { //change this to your database needs //String categoryID = // LettersDataList.DataKeys[e.Item.ItemIndex].ToString(); //String categoryName = // ((TextBox)e.Item.FindControl("textCategoryName")).Text; //String description = // ((TextBox)e.Item.FindControl("textDescription")).Text; //SqlDataSource1.UpdateParameters["original_CategoryID"].DefaultValue // = categoryID; //SqlDataSource1.UpdateParameters["categoryName"].DefaultValue // = categoryName; //SqlDataSource1.UpdateParameters["Description"].DefaultValue // = description; //SqlDataSource1.Update(); LettersDataList.EditItemIndex = -1; LettersDataList.DataBind(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload