Problem with Updating Option in DataList Control

Sep 9 2008 3:06 AM

InCoding

int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);

 

        TextBox t = e.Item.FindControl("txtProductName") as TextBox;

        TextBox t1 = e.Item.FindControl("txtShortDescription") as TextBox;

        TextBox t2 = e.Item.FindControl("txtLongDescription") as TextBox;

        TextBox t3 = e.Item.FindControl("txtVendor") as TextBox;

        //TextBox pName = (TextBox)e.Item.FindControl("txtProductName");

        //TextBox sdesc = (TextBox)e.Item.FindControl("txtShortDescription");

        //TextBox lDesc = (TextBox)e.Item.FindControl("txtLongDescription");

        //TextBox vendor = (TextBox)e.Item.FindControl("txtVendor");

        String queryUpd = "UPDATE Product SET ProductName= @ProductName,ShortDescription= @ShortDescription,LongDescription=@LongDescription,Vendor= @Vendor WHERE Pid=@id";

        SqlCommand cmd = new SqlCommand(queryUpd, con);

        cmd.Parameters.Add("@ProductName", SqlDbType.VarChar).Value = t.Text;

        cmd.Parameters.Add("@ShortDescription", SqlDbType.VarChar).Value = t1.Text;

        cmd.Parameters.Add("@LongDescription", SqlDbType.VarChar).Value = t2.Text;

        cmd.Parameters.Add("@Vendor", SqlDbType.VarChar).Value = t3.Text;

        cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;

        con.Open();

        cmd.ExecuteNonQuery();

        con.Close();

        DataList1.EditItemIndex = -1;

        BindData();

In Source

<EditItemTemplate>

      <table border="1">

      <tr><td><b>Pid : </b></td>

         <td>'<%# DataBinder.Eval(Container.DataItem, "Pid") %>'

         </td></tr>

         <tr><td><b>ProductName : </b></td>

         <td><asp:TextBox Text='<%# Eval("ProductName") %>' runat="server" ID="txtProductName"/>

         </td></tr>

         <tr><td><b>ShortDescription: </b></td>

         <td><asp:TextBox Text='<%# Eval("ShortDescription") %>' runat="server" ID="txtShortDescription"/>

          </td></tr>

          <tr><td><b>LongDescription: </b></td>

         <td><asp:TextBox Text='<%# Eval("LongDescription") %>' runat="server" ID="txtLongDescription"/>

          </td></tr>

          <tr><td><b>Vendor: </b></td>

         <td><asp:TextBox Text='<%# Eval("Vendor") %>' runat="server" ID="txtVendor"/>

          </td></tr>

        

</table>

 

Problem:

 

When I am clicking Edit Link Button: it’s changing to Textboxes.

But after I made changes in the textboxes, Variables are not receiving the Updated Textbox Values.

It receiving from Database for Corresponding Columns.

Please Check it and Tell me..


Answers (1)