473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Datalist: update a datasource without using select/edit/update

Hi,

I need a solution for the following problem:

In the item template of a datalist control I have already
a button control with the commandname set to "select" to
perform some specific database action. I additionally want
to update an integer value in the underlying data source
by simply clicking an a check box or an imagebutton
WITHOUT USING THE EDIT/UPDATE COMMANDNAME property of the
datalist. So for example the datasource should be updated,
whenever the checkbox checked-property changes.

I tried two methods without success:

(1) If I use the OnCheckedChanged-event and set the
autopostback property to true, I cannot access the
SelectedIndex of the datalist in the event handler. But
this is the primary key of the datasource and is necesary
for the update. Accessing other objects of the item
template (e.g. a textbox which holds the primary key) is
not possible as well.

(2) I tried to use a second imagebutton instead of the
checkbox and set the commandname of the imagebutton
to "select" as well. Then everything is OK

with the SelectedIndex, but how can I determine, which of
the two different "Select" buttons has been clicked? I
need to know which one, because I have to perform
different tasks.

Thanks in advance.

Regards

Hartmut
Nov 18 '05 #1
3 2498
Hi Hartmut,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue. I am researching on it and will update you
as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #2
Hi Hartmut,

Based on my research and experience, you can distinguish these buttons by
using the CommandArgument property. For example,

1. Assign the different values to the CommandArgument properties of the
button and imagebutton inside the datalist
2. Hook the ItemCommand event of the datalist control. this event fires
when a button inside the datalist was clicked and it also fires before the
SelectedIndexChanged event.
3. In the ItemCommand event, get the value of the CommandArgument property
via the e argument of the event. With the different value of the
CommandArgument property, you should know which button was clicked.
4. In the subsequent SelectedIndexChanged event you can do different things
according to the different CommandArgument

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #3
Hi Jacob,

thank you for yout cool hint. It solves my problem exactly.

Best regards

Hartmut Schroth
-----Original Message-----
Hi Hartmut,

Based on my research and experience, you can distinguish these buttons by using the CommandArgument property. For example,

1. Assign the different values to the CommandArgument properties of the button and imagebutton inside the datalist
2. Hook the ItemCommand event of the datalist control. this event fires when a button inside the datalist was clicked and it also fires before the SelectedIndexChanged event.
3. In the ItemCommand event, get the value of the CommandArgument property via the e argument of the event. With the different value of the CommandArgument property, you should know which button was clicked.4. In the subsequent SelectedIndexChanged event you can do different things according to the different CommandArgument

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Hardy Wang | last post by:
Hi all; I have a DataList with ItemCreated event like below: private void myList_ItemCreated(object sender , DataListItemEventArgs e) { DataRowView myRowView; DataRow myRow; if (e.Item.DataItem...
0
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page ...
0
by: VbScripter | last post by:
In the code below, I have an editItemTemplate that will have to have a long list of ip's bound to it. The problem is that the lisbox is not seen by asp.net until after the datalist containing it...
2
by: mahsa | last post by:
Hi I have a Datalist that can Update each row my problem is i have a edit update and remove link in datalist when user click edit it show update and cancel button but when they click update button it...
10
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...
1
by: Neil Jarman | last post by:
Hi, I'm new to this today, and I've got some test code (see below.) The data loads fine. I can't understand why any of the events fire. Once the page loads, clicking on thew button from the...
3
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
2
tjc0ol
by: tjc0ol | last post by:
Hi guys, Im just wondering that I cannot update my database throught datagrid datalist control, and the only thing works is that I can delete, cancel, edit but when I clicked update link...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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
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
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,...

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.