C# Datalist control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teju
    New Member
    • Jul 2006
    • 34

    C# Datalist control

    Hi all,
    I am using datalist control to display, edit, update and delete records in c#.
    Displaying works fine, but the problem is while updating the record. I am trying to access the changed value from the text box and run the update command, but everytime i try to update, it gives me the old text box value.
    I have tried state value as well but doesn't help.
    Code:
    TextBox tbox = (TextBox)e.Item.FindControl("TextBox1");
      string newdate = tbox.Text;//This gives me the value which is already in the database but not the new value which i have entered in the text box//
    I don't understand wat is the problem.

    Please help.
    Thanks
  • vanc
    Recognized Expert New Member
    • Mar 2007
    • 211

    #2
    I think the problem may come in the update code, or you can detailed your codes.
    What is variable e? object or EventArguments?

    cheers.

    Comment

    • teju
      New Member
      • Jul 2006
      • 34

      #3
      Originally posted by vanc
      I think the problem may come in the update code, or you can detailed your codes.
      What is variable e? object or EventArguments?

      cheers.
      Hello, below is my code
      [code]
      ///update code
      void myListUpdateHan dler(Object src, DataListCommand EventArgs e)
      {
      if (e.CommandName == "update")
      {

      SqlConnection myConnection = new SqlConnection(C onfigurationSet tings.AppSettin gs["xxxxxx"]);

      TextBox tbox = (TextBox)e.Item .FindControl("T extBox1");
      string newdate = tbox.Text;
      int id = (int)YearNewsLi st.DataKeys[e.Item.ItemInde x];

      Response.Write( id);

      string strSQL = "Update xxx set ExpDate='" + newdate + "' WHERE ID=" + id;
      Response.Write( strSQL);
      // SqlCommand myupdateCom = new SqlCommand(strS QL);
      //Response.Write( strSQL);

      //myupdateCom.Con nection = myConnection;
      //myConnection.Op en();
      //myupdateCom.Exe cuteNonQuery();
      //smyupdateCom.Co nnection.Close( );



      YearNewsList.Ed itItemIndex = -1;
      YearNewsList.Da taBind();

      }
      }

      //datalist edittemplate

      <EditItemTempla te>

      <tr>
      <td width="100" style="font-size:10pt"><fon t face="Arial">
      <b><%# DataBinder.Eval (Container.Data Item, "EntryDate" , "{0:d}") %></b>
      </font>
      </td>
      <td style="font-size:10pt"><fon t face="Arial">
      <%# DataBinder.Eval (Container.Data Item, "Title") %>
      </font>
      </td>

      <td style="font-size:10pt"><fon t face="Arial">
      <asp:TextBox ID="TextBox1" runat="server" Text=""
      ></asp:TextBox>

      </font></td>


      <td align=right style="font-size:10pt"><fon t face="Arial">
      <b>

      <asp:LinkButt on id="LinkButton3 "
      Text="Update"
      CommandName="up date"

      runat="server"/>
      </b>
      </font></td>

      <td align=right style="font-size:10pt"><fon t face="Arial">
      <b>

      <asp:LinkButt on id="LinkButton4 "
      Text="Cancel"
      CommandName="Ca ncel"
      runat="server"/>
      </EditItemTemplat e>



      Thanks for your help

      Comment

      Working...