473,508 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Datalist control

34 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. TextBox tbox = (TextBox)e.Item.FindControl("TextBox1");
  2.   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//
  3.  
  4.  
I don't understand wat is the problem.

Please help.
Thanks
Jul 3 '07 #1
2 1628
vanc
211 Recognized Expert New Member
I think the problem may come in the update code, or you can detailed your codes.
What is variable e? object or EventArguments?

cheers.
Jul 4 '07 #2
teju
34 New Member
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
Jul 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4548
by: Mike Malter | last post by:
I take it that the only way to add rows to a DataList control is through DataBind? If not, how do I manually add rows to a DataList control? I have searched everywhere and can't find an example...
10
2820
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
6
2178
by: tshad | last post by:
I need to get to a status label I have on my footer section of my datalist. There is no event happening that would go to the footer. I am just doing some processing and want to update the label...
4
4028
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
3419
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
1
3952
by: shantanu_kush | last post by:
Hi there, I am using a DataList in a composite control. The DataList has an Custom ItemTemplate(ITemplate) which adds a Button to the DataList Item as shown in the code below : public class...
1
3895
by: Jim in Arizona | last post by:
I'm don't know how I would get around this. When working with a datalist control, there a specific built in commands (OnEditCommand, OnCancelCommand, etc). These commands, when the datalist...
6
2206
by: Victor | last post by:
Hi. all I have a customize web control. I have three simple properties and customized render class. then I add this control into my datalist like <asp:DataList ID="datalist" runat="server"...
3
2794
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
4
3971
by: Peter | last post by:
I have a DataList and each item in the datalist has an imge, I want to change the datalist item image on the client side when user clicks a button. How would I do that with JavaScript, does anyone...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.