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

Discussion in 'ASP .Net' started by Hartmut Schroth, Nov 27, 2003.

  1. 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
     
    Hartmut Schroth, Nov 27, 2003
    #1
    1. Advertising

  2. 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.
     
    Jacob Yang [MSFT], Nov 28, 2003
    #2
    1. Advertising

  3. 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.
     
    Jacob Yang [MSFT], Nov 29, 2003
    #3
  4. 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.
    >
    >.
    >
     
    Hartmut Schroth, Dec 1, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,961
  2. =?Utf-8?B?RGFiYmxlcg==?=

    select gridview row without using select button?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    101,627
    dch31969
    Feb 27, 2009
  3. Vivek
    Replies:
    0
    Views:
    512
    Vivek
    Dec 14, 2007
  4. Bob Clegg

    Select then expose Edit-Update-Cancel column

    Bob Clegg, Jan 23, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    143
    Bob Clegg
    Jan 25, 2004
  5. Henke

    Update without using Edit and Update button

    Henke, May 30, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    166
    Brock Allen
    Jun 1, 2006
Loading...

Share This Page