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 myListUpdateHandler(Object src, DataListCommandEventArgs e)
{
if (e.CommandName == "update")
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["xxxxxx"]);
TextBox tbox = (TextBox)e.Item.FindControl("TextBox1");
string newdate = tbox.Text;
int id = (int)YearNewsList.DataKeys[e.Item.ItemIndex];
Response.Write(id);
string strSQL = "Update xxx set ExpDate='" + newdate + "' WHERE ID=" + id;
Response.Write(strSQL);
// SqlCommand myupdateCom = new SqlCommand(strSQL);
//Response.Write(strSQL);
//myupdateCom.Connection = myConnection;
//myConnection.Open();
//myupdateCom.ExecuteNonQuery();
//smyupdateCom.Connection.Close();
YearNewsList.EditItemIndex = -1;
YearNewsList.DataBind();
}
}
//datalist edittemplate
<EditItemTemplate>
<tr>
<td width="100" style="font-size:10pt"><font face="Arial">
<b><%# DataBinder.Eval(Container.DataItem, "EntryDate" , "{0:d}") %></b>
</font>
</td>
<td style="font-size:10pt"><font face="Arial">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</font>
</td>
<td style="font-size:10pt"><font face="Arial">
<asp:TextBox ID="TextBox1" runat="server" Text=""
></asp:TextBox>
</font></td>
<td align=right style="font-size:10pt"><font face="Arial">
<b>
<asp:LinkButton id="LinkButton3"
Text="Update"
CommandName="update"
runat="server"/>
</b>
</font></td>
<td align=right style="font-size:10pt"><font face="Arial">
<b>
<asp:LinkButton id="LinkButton4"
Text="Cancel"
CommandName="Cancel"
runat="server"/>
</EditItemTemplate>
Thanks for your help