473,761 Members | 9,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 OnCheckedChange d-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 2528
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
SelectedIndexCh anged 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 SelectedIndexCh anged 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 SelectedIndexC hanged 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 CommandArgumen t property, you should know which button was clicked.4. In the subsequent SelectedIndexCh anged 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
4731
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 != null) { Trace.Write(e.Item.ItemType.ToString(), "---with data"); } else { Trace.Write(e.Item.ItemType.ToString(), "---without data"); }
0
1766
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 Private strConn As String =
0
1925
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 is exposed. Is there a way to bind the ddl inside of an already databound templated column? Thanks , of course Michael
2
1101
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 again show update and cancle I want it to show edit button and dont show update and cancel do you have any idea?
10
2856
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 have to add a datalist control. Using this datalist control I should be able to add edit, modify and cancel the items listed in this control. Here is how I designed. I used placeholder to add the controls dynamically to the page on the click...
1
2151
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 ItemTemplate does not fire the OnItemCommand event. It just fires a page reload - as a postback. I guess I'm missing something really obvious and important here?
3
10303
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 (where is the child DataList).... But in case I want to make Edit in this child DataList it is not working... No edit template showed... :( this is a code that i use for the child DataList... Edit command // this is for child DataList...
2
1782
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 there's an error that says: "Syntax error in UPDATE statement." I wonder what's wrong with my code and how to correct this one? Below are my codes: OleDbConnection objConn = new OleDbConnection( "Provider=Microsoft.Jet.OleDb.4.0;" + "Data...
3
2811
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 need to control the visibility of a textbox based on a dropdown selection in the datalist's edititem template. To do this, I registered a client script block function and attached a client side handler for the dropdownlist's onchange event in the...
0
9522
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9948
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.