DataGrid ButtonColumn

Discussion in 'ASP .Net' started by rn5a@rediffmail.com, Mar 11, 2007.

  1. Guest

    A DataGrid is populated with the records existing in a database. Each
    of the row in this DataGrid has a ButtonColumn. Assume that the
    DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    the DataGrid (of course, except the Header & the Footer) is
    accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    DataGrid.

    The Buttons that get rendered by the ButtonColumns - how do I get the
    ID of each of these Buttons?
    , Mar 11, 2007
    #1
    1. Advertising

  2. On Mar 11, 9:14 pm, wrote:
    > A DataGrid is populated with the records existing in a database. Each
    > of the row in this DataGrid has a ButtonColumn. Assume that the
    > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > the DataGrid (of course, except the Header & the Footer) is
    > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > DataGrid.
    >
    > The Buttons that get rendered by the ButtonColumns - how do I get the
    > ID of each of these Buttons?


    The IDs for each button are autogenerated by the ButtonColumns. If you
    need to find which row has to be updated (which button has been
    clicked) you don't need to have IDs, you should use the CommandName
    property and OnItemCommand event...

    For example:

    protected void DataGrid1_OnItemCommand(Object sender,
    DataGridCommandEventArgs e)
    {
    if(e.CommandName=="delete")
    {
    sql = "DELETE FROM... WHERE id=" +
    DataGrid1.DataKeys(CInt(e.Item.ItemIndex))
    }
    }
    Alexey Smirnov, Mar 11, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 12, 1:37 am, "Alexey Smirnov" <> wrote:
    > On Mar 11, 9:14 pm, wrote:
    >
    > > A DataGrid is populated with the records existing in a database. Each
    > > of the row in this DataGrid has a ButtonColumn. Assume that the
    > > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > > the DataGrid (of course, except the Header & the Footer) is
    > > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > > DataGrid.

    >
    > > The Buttons that get rendered by the ButtonColumns - how do I get the
    > > ID of each of these Buttons?

    >
    > The IDs for each button are autogenerated by the ButtonColumns. If you
    > need to find which row has to be updated (which button has been
    > clicked) you don't need to have IDs, you should use the CommandName
    > property and OnItemCommand event...
    >
    > For example:
    >
    > protected void DataGrid1_OnItemCommand(Object sender,
    > DataGridCommandEventArgs e)
    > {
    > if(e.CommandName=="delete")
    > {
    > sql = "DELETE FROM... WHERE id=" +
    > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))
    >
    >
    >
    > }
    > }- Hide quoted text -
    >
    > - Show quoted text -


    Well, Alexey, my main intention to get the IDs of each of the buttons
    is to disable the button immediately after the button is clicked for
    the first time so that I can prevent users from clicking the button
    again & again to avoid posting the same data over & over again.

    Any idea how could I do this?

    Thanks for the prompt response.
    , Mar 11, 2007
    #3
  4. On Mar 11, 9:56 pm, wrote:
    > On Mar 12, 1:37 am, "Alexey Smirnov" <> wrote:
    >
    >
    >
    >
    >
    > > On Mar 11, 9:14 pm, wrote:

    >
    > > > A DataGrid is populated with the records existing in a database. Each
    > > > of the row in this DataGrid has a ButtonColumn. Assume that the
    > > > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > > > the DataGrid (of course, except the Header & the Footer) is
    > > > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > > > DataGrid.

    >
    > > > The Buttons that get rendered by the ButtonColumns - how do I get the
    > > > ID of each of these Buttons?

    >
    > > The IDs for each button are autogenerated by the ButtonColumns. If you
    > > need to find which row has to be updated (which button has been
    > > clicked) you don't need to have IDs, you should use the CommandName
    > > property and OnItemCommand event...

    >
    > > For example:

    >
    > > protected void DataGrid1_OnItemCommand(Object sender,
    > > DataGridCommandEventArgs e)
    > > {
    > > if(e.CommandName=="delete")
    > > {
    > > sql = "DELETE FROM... WHERE id=" +
    > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))

    >
    > > }
    > > }- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Well, Alexey, my main intention to get the IDs of each of the buttons
    > is to disable the button immediately after the button is clicked for
    > the first time so that I can prevent users from clicking the button
    > again & again to avoid posting the same data over & over again.
    >
    > Any idea how could I do this?
    >
    > Thanks for the prompt response.- Hide quoted text -
    >
    > - Show quoted text -


    I think something like this

    protected void DataGrid1_OnItemCommand(Object sender,
    DataGridCommandEventArgs e)
    {
    if(e.CommandName=="delete")
    {

    ----------------------------------------------------------------------------
    Button myButton = (Button) e.CommandSource;
    myButton.Enabled = false;
    ----------------------------------------------------------------------------

    sql = "DELETE FROM... WHERE id=" +
    DataGrid1.DataKeys(CInt(e.Item.ItemIndex))
    Alexey Smirnov, Mar 11, 2007
    #4
  5. Guest

    On Mar 12, 2:25 am, "Alexey Smirnov" <> wrote:
    > On Mar 11, 9:56 pm, wrote:
    >
    >
    >
    >
    >
    > > On Mar 12, 1:37 am, "Alexey Smirnov" <> wrote:

    >
    > > > On Mar 11, 9:14 pm, wrote:

    >
    > > > > A DataGrid is populated with the records existing in a database. Each
    > > > > of the row in this DataGrid has a ButtonColumn. Assume that the
    > > > > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > > > > the DataGrid (of course, except the Header & the Footer) is
    > > > > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > > > > DataGrid.

    >
    > > > > The Buttons that get rendered by the ButtonColumns - how do I get the
    > > > > ID of each of these Buttons?

    >
    > > > The IDs for each button are autogenerated by the ButtonColumns. If you
    > > > need to find which row has to be updated (which button has been
    > > > clicked) you don't need to have IDs, you should use the CommandName
    > > > property and OnItemCommand event...

    >
    > > > For example:

    >
    > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > DataGridCommandEventArgs e)
    > > > {
    > > > if(e.CommandName=="delete")
    > > > {
    > > > sql = "DELETE FROM... WHERE id=" +
    > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))

    >
    > > > }
    > > > }- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > Well, Alexey, my main intention to get the IDs of each of the buttons
    > > is to disable the button immediately after the button is clicked for
    > > the first time so that I can prevent users from clicking the button
    > > again & again to avoid posting the same data over & over again.

    >
    > > Any idea how could I do this?

    >
    > > Thanks for the prompt response.- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > I think something like this
    >
    > protected void DataGrid1_OnItemCommand(Object sender,
    > DataGridCommandEventArgs e)
    > {
    > if(e.CommandName=="delete")
    > {
    >
    > ---------------------------------------------------------------------------­-
    > Button myButton = (Button) e.CommandSource;
    > myButton.Enabled = false;
    > ---------------------------------------------------------------------------­-
    >
    > sql = "DELETE FROM... WHERE id=" +
    > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))- Hide quoted text -
    >
    > - Show quoted text -


    Alexey, what is the VB equivalent of (Button) e.CommandSource?

    Also what if I replace the ButtonColumn with an EditCommandColumn?
    , Mar 11, 2007
    #5
  6. On Mar 11, 10:57 pm, wrote:
    > On Mar 12, 2:25 am, "Alexey Smirnov" <> wrote:
    >
    >
    >
    >
    >
    > > On Mar 11, 9:56 pm, wrote:

    >
    > > > On Mar 12, 1:37 am, "Alexey Smirnov" <> wrote:

    >
    > > > > On Mar 11, 9:14 pm, wrote:

    >
    > > > > > A DataGrid is populated with the records existing in a database. Each
    > > > > > of the row in this DataGrid has a ButtonColumn. Assume that the
    > > > > > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > > > > > the DataGrid (of course, except the Header & the Footer) is
    > > > > > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > > > > > DataGrid.

    >
    > > > > > The Buttons that get rendered by the ButtonColumns - how do I get the
    > > > > > ID of each of these Buttons?

    >
    > > > > The IDs for each button are autogenerated by the ButtonColumns. If you
    > > > > need to find which row has to be updated (which button has been
    > > > > clicked) you don't need to have IDs, you should use the CommandName
    > > > > property and OnItemCommand event...

    >
    > > > > For example:

    >
    > > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > > DataGridCommandEventArgs e)
    > > > > {
    > > > > if(e.CommandName=="delete")
    > > > > {
    > > > > sql = "DELETE FROM... WHERE id=" +
    > > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))

    >
    > > > > }
    > > > > }- Hide quoted text -

    >
    > > > > - Show quoted text -

    >
    > > > Well, Alexey, my main intention to get the IDs of each of the buttons
    > > > is to disable the button immediately after the button is clicked for
    > > > the first time so that I can prevent users from clicking the button
    > > > again & again to avoid posting the same data over & over again.

    >
    > > > Any idea how could I do this?

    >
    > > > Thanks for the prompt response.- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > I think something like this

    >
    > > protected void DataGrid1_OnItemCommand(Object sender,
    > > DataGridCommandEventArgs e)
    > > {
    > > if(e.CommandName=="delete")
    > > {

    >
    > > ---------------------------------------------------------------------------­­-
    > > Button myButton = (Button) e.CommandSource;
    > > myButton.Enabled = false;
    > > ---------------------------------------------------------------------------­­-

    >
    > > sql = "DELETE FROM... WHERE id=" +
    > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Alexey, what is the VB equivalent of (Button) e.CommandSource?


    Dim myButton as Button = CType(e.CommandSource, Button)


    > Also what if I replace the ButtonColumn with an EditCommandColumn?- Hide quoted text -
    >


    I think it should be similar
    Alexey Smirnov, Mar 11, 2007
    #6
  7. Guest

    On Mar 12, 3:05 am, "Alexey Smirnov" <> wrote:
    > On Mar 11, 10:57 pm, wrote:
    >
    >
    >
    >
    >
    > > On Mar 12, 2:25 am, "Alexey Smirnov" <> wrote:

    >
    > > > On Mar 11, 9:56 pm, wrote:

    >
    > > > > On Mar 12, 1:37 am, "Alexey Smirnov" <> wrote:

    >
    > > > > > On Mar 11, 9:14 pm, wrote:

    >
    > > > > > > A DataGrid is populated with the records existing in a database.. Each
    > > > > > > of the row in this DataGrid has a ButtonColumn. Assume that the
    > > > > > > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > > > > > > the DataGrid (of course, except the Header & the Footer) is
    > > > > > > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > > > > > > DataGrid.

    >
    > > > > > > The Buttons that get rendered by the ButtonColumns - how do I get the
    > > > > > > ID of each of these Buttons?

    >
    > > > > > The IDs for each button are autogenerated by the ButtonColumns. If you
    > > > > > need to find which row has to be updated (which button has been
    > > > > > clicked) you don't need to have IDs, you should use the CommandName
    > > > > > property and OnItemCommand event...

    >
    > > > > > For example:

    >
    > > > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > > > DataGridCommandEventArgs e)
    > > > > > {
    > > > > > if(e.CommandName=="delete")
    > > > > > {
    > > > > > sql = "DELETE FROM... WHERE id=" +
    > > > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))

    >
    > > > > > }
    > > > > > }- Hide quoted text -

    >
    > > > > > - Show quoted text -

    >
    > > > > Well, Alexey, my main intention to get the IDs of each of the buttons
    > > > > is to disable the button immediately after the button is clicked for
    > > > > the first time so that I can prevent users from clicking the button
    > > > > again & again to avoid posting the same data over & over again.

    >
    > > > > Any idea how could I do this?

    >
    > > > > Thanks for the prompt response.- Hide quoted text -

    >
    > > > > - Show quoted text -

    >
    > > > I think something like this

    >
    > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > DataGridCommandEventArgs e)
    > > > {
    > > > if(e.CommandName=="delete")
    > > > {

    >
    > > > ---------------------------------------------------------------------------­­­-
    > > > Button myButton = (Button) e.CommandSource;
    > > > myButton.Enabled = false;
    > > > ---------------------------------------------------------------------------­­­-

    >
    > > > sql = "DELETE FROM... WHERE id=" +
    > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > Alexey, what is the VB equivalent of (Button) e.CommandSource?

    >
    > Dim myButton as Button = CType(e.CommandSource, Button)
    >
    > > Also what if I replace the ButtonColumn with an EditCommandColumn?- Hide quoted text -

    >
    > I think it should be similar- Hide quoted text -
    >
    > - Show quoted text -


    > Dim myButton as Button = CType(e.CommandSource, Button)


    Yeah....that's exactly what I did but overall, your suggestion doesn't
    work, Alexey.

    Since I am working on my local intranet where clicking a button
    immediately executes a sub, I added the following code in the
    DataGrid's ItemCommand event:

    Sub dg1_ItemCommand(.......)
    Dim i As Integer
    Dim btn As Button

    If (ea.CommandName = "delete") Then
    btn = CType(ea.CommandSource, Button)
    btn.Enabled = False

    For i = 0 To 1000000000
    Response.Write(i)
    Next
    End If
    End Sub

    Note the For.....Next loop. I added that loop to prolong the Form
    submission to verify whether the button actually gets disabled or not
    after it is clicked for the first time but it doesn't get disabled; it
    remains enabled even after the button is clicked for the first time.

    Any other ideas/suggestions?
    , Mar 11, 2007
    #7
  8. On Mar 11, 11:46 pm, wrote:
    > On Mar 12, 3:05 am, "Alexey Smirnov" <> wrote:
    >
    >
    >
    >
    >
    > > On Mar 11, 10:57 pm, wrote:

    >
    > > > On Mar 12, 2:25 am, "Alexey Smirnov" <> wrote:

    >
    > > > > On Mar 11, 9:56 pm, wrote:

    >
    > > > > > On Mar 12, 1:37 am, "Alexey Smirnov" <> wrote:

    >
    > > > > > > On Mar 11, 9:14 pm, wrote:

    >
    > > > > > > > A DataGrid is populated with the records existing in a database. Each
    > > > > > > > of the row in this DataGrid has a ButtonColumn. Assume that the
    > > > > > > > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > > > > > > > the DataGrid (of course, except the Header & the Footer) is
    > > > > > > > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > > > > > > > DataGrid.

    >
    > > > > > > > The Buttons that get rendered by the ButtonColumns - how do I get the
    > > > > > > > ID of each of these Buttons?

    >
    > > > > > > The IDs for each button are autogenerated by the ButtonColumns. If you
    > > > > > > need to find which row has to be updated (which button has been
    > > > > > > clicked) you don't need to have IDs, you should use the CommandName
    > > > > > > property and OnItemCommand event...

    >
    > > > > > > For example:

    >
    > > > > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > > > > DataGridCommandEventArgs e)
    > > > > > > {
    > > > > > > if(e.CommandName=="delete")
    > > > > > > {
    > > > > > > sql = "DELETE FROM... WHERE id=" +
    > > > > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))

    >
    > > > > > > }
    > > > > > > }- Hide quoted text -

    >
    > > > > > > - Show quoted text -

    >
    > > > > > Well, Alexey, my main intention to get the IDs of each of the buttons
    > > > > > is to disable the button immediately after the button is clicked for
    > > > > > the first time so that I can prevent users from clicking the button
    > > > > > again & again to avoid posting the same data over & over again.

    >
    > > > > > Any idea how could I do this?

    >
    > > > > > Thanks for the prompt response.- Hide quoted text -

    >
    > > > > > - Show quoted text -

    >
    > > > > I think something like this

    >
    > > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > > DataGridCommandEventArgs e)
    > > > > {
    > > > > if(e.CommandName=="delete")
    > > > > {

    >
    > > > > ---------------------------------------------------------------------------­­­­-
    > > > > Button myButton = (Button) e.CommandSource;
    > > > > myButton.Enabled = false;
    > > > > ---------------------------------------------------------------------------­­­­-

    >
    > > > > sql = "DELETE FROM... WHERE id=" +
    > > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))- Hide quoted text -

    >
    > > > > - Show quoted text -

    >
    > > > Alexey, what is the VB equivalent of (Button) e.CommandSource?

    >
    > > Dim myButton as Button = CType(e.CommandSource, Button)

    >
    > > > Also what if I replace the ButtonColumn with an EditCommandColumn?- Hide quoted text -

    >
    > > I think it should be similar- Hide quoted text -

    >
    > > - Show quoted text -
    > > Dim myButton as Button = CType(e.CommandSource, Button)

    >
    > Yeah....that's exactly what I did but overall, your suggestion doesn't
    > work, Alexey.
    >
    > Since I am working on my local intranet where clicking a button
    > immediately executes a sub, I added the following code in the
    > DataGrid's ItemCommand event:
    >
    > Sub dg1_ItemCommand(.......)
    > Dim i As Integer
    > Dim btn As Button
    >
    > If (ea.CommandName = "delete") Then
    > btn = CType(ea.CommandSource, Button)
    > btn.Enabled = False
    >
    > For i = 0 To 1000000000
    > Response.Write(i)
    > Next
    > End If
    > End Sub
    >
    > Note the For.....Next loop. I added that loop to prolong the Form
    > submission to verify whether the button actually gets disabled or not
    > after it is clicked for the first time but it doesn't get disabled; it
    > remains enabled even after the button is clicked for the first time.
    >
    > Any other ideas/suggestions?- Hide quoted text -
    >
    > - Show quoted text -


    For.....Next has nothing to do with the button, don't you think?

    Enabled = False should change the button to grey, and user will not be
    able to click it once more (For.....Next can be executed only once per
    row item)
    Alexey Smirnov, Mar 12, 2007
    #8
  9. Guest

    On Mar 12, 12:25 pm, "Alexey Smirnov" <>
    wrote:
    > On Mar 11, 11:46 pm, wrote:
    >
    >
    >
    >
    >
    > > On Mar 12, 3:05 am, "Alexey Smirnov" <> wrote:

    >
    > > > On Mar 11, 10:57 pm, wrote:

    >
    > > > > On Mar 12, 2:25 am, "Alexey Smirnov" <> wrote:

    >
    > > > > > On Mar 11, 9:56 pm, wrote:

    >
    > > > > > > On Mar 12, 1:37 am, "Alexey Smirnov" <> wrote:

    >
    > > > > > > > On Mar 11, 9:14 pm, wrote:

    >
    > > > > > > > > A DataGrid is populated with the records existing in a database. Each
    > > > > > > > > of the row in this DataGrid has a ButtonColumn. Assume that the
    > > > > > > > > DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each row in
    > > > > > > > > the DataGrid (of course, except the Header & the Footer) is
    > > > > > > > > accompanied by a ButtonColumn i.e. there are 10 Buttons in the
    > > > > > > > > DataGrid.

    >
    > > > > > > > > The Buttons that get rendered by the ButtonColumns - how do I get the
    > > > > > > > > ID of each of these Buttons?

    >
    > > > > > > > The IDs for each button are autogenerated by the ButtonColumns. If you
    > > > > > > > need to find which row has to be updated (which button has been
    > > > > > > > clicked) you don't need to have IDs, you should use the CommandName
    > > > > > > > property and OnItemCommand event...

    >
    > > > > > > > For example:

    >
    > > > > > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > > > > > DataGridCommandEventArgs e)
    > > > > > > > {
    > > > > > > > if(e.CommandName=="delete")
    > > > > > > > {
    > > > > > > > sql = "DELETE FROM... WHERE id=" +
    > > > > > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))

    >
    > > > > > > > }
    > > > > > > > }- Hide quoted text -

    >
    > > > > > > > - Show quoted text -

    >
    > > > > > > Well, Alexey, my main intention to get the IDs of each of the buttons
    > > > > > > is to disable the button immediately after the button is clicked for
    > > > > > > the first time so that I can prevent users from clicking the button
    > > > > > > again & again to avoid posting the same data over & over again.

    >
    > > > > > > Any idea how could I do this?

    >
    > > > > > > Thanks for the prompt response.- Hide quoted text -

    >
    > > > > > > - Show quoted text -

    >
    > > > > > I think something like this

    >
    > > > > > protected void DataGrid1_OnItemCommand(Object sender,
    > > > > > DataGridCommandEventArgs e)
    > > > > > {
    > > > > > if(e.CommandName=="delete")
    > > > > > {

    >
    > > > > > ---------------------------------------------------------------------------­­­­­-
    > > > > > Button myButton = (Button) e.CommandSource;
    > > > > > myButton.Enabled = false;
    > > > > > ---------------------------------------------------------------------------­­­­­-

    >
    > > > > > sql = "DELETE FROM... WHERE id=" +
    > > > > > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))- Hide quoted text -

    >
    > > > > > - Show quoted text -

    >
    > > > > Alexey, what is the VB equivalent of (Button) e.CommandSource?

    >
    > > > Dim myButton as Button = CType(e.CommandSource, Button)

    >
    > > > > Also what if I replace the ButtonColumn with an EditCommandColumn?- Hide quoted text -

    >
    > > > I think it should be similar- Hide quoted text -

    >
    > > > - Show quoted text -
    > > > Dim myButton as Button = CType(e.CommandSource, Button)

    >
    > > Yeah....that's exactly what I did but overall, your suggestion doesn't
    > > work, Alexey.

    >
    > > Since I am working on my local intranet where clicking a button
    > > immediately executes a sub, I added the following code in the
    > > DataGrid's ItemCommand event:

    >
    > > Sub dg1_ItemCommand(.......)
    > > Dim i As Integer
    > > Dim btn As Button

    >
    > > If (ea.CommandName = "delete") Then
    > > btn = CType(ea.CommandSource, Button)
    > > btn.Enabled = False

    >
    > > For i = 0 To 1000000000
    > > Response.Write(i)
    > > Next
    > > End If
    > > End Sub

    >
    > > Note the For.....Next loop. I added that loop to prolong the Form
    > > submission to verify whether the button actually gets disabled or not
    > > after it is clicked for the first time but it doesn't get disabled; it
    > > remains enabled even after the button is clicked for the first time.

    >
    > > Any other ideas/suggestions?- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > For.....Next has nothing to do with the button, don't you think?
    >
    > Enabled = False should change the button to grey, and user will not be
    > able to click it once more (For.....Next can be executed only once per
    > row item)- Hide quoted text -
    >
    > - Show quoted text -


    But Alexey Enabled = False DOESN'T disable the button after the button
    is clicked. & I am saying this after trying out Enabled = False
    repeatedly. The button just refuses to grey out after the first click.
    , Mar 12, 2007
    #9
  10. On Mar 12, 10:13 am, wrote:

    > But Alexey Enabled = False DOESN'T disable the button after the button
    > is clicked. & I am saying this after trying out Enabled = False
    > repeatedly. The button just refuses to grey out after the first click.- Hide quoted text -


    For me it works.

    My code:

    The grid

    <asp:DataGrid ID="DataGrid1" OnItemCommand="DataGrid1_ItemCommand"...
    <Columns>
    ....
    <asp:ButtonColumn Text="Delete" CommandName="Delete"
    ButtonType="PushButton"></asp:ButtonColumn>
    </Columns>
    </asp:DataGrid>

    Code-behind:

    Sub DataGrid1_ItemCommand(ByVal Source As Object, ByVal e As
    DataGridCommandEventArgs)
    If (e.CommandName = "Delete") Then
    Dim btn As Button = CType(e.CommandSource, Button)
    btn.Enabled = False
    End If
    End Sub

    The code above disable the button once it clicked.

    Note, that the ButtonColumn can have another ButtonType="LinkButton".
    For this type of button you should use another cast

    Dim btn As LinkButton = CType(e.CommandSource, LinkButton)

    This will disable the button (actually the link) too.
    Alexey Smirnov, Mar 12, 2007
    #10
    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. Northern
    Replies:
    0
    Views:
    403
    Northern
    Jul 22, 2003
  2. CGuy
    Replies:
    2
    Views:
    2,013
  3. John
    Replies:
    3
    Views:
    3,239
    Giorgio Parmeggiani
    Nov 3, 2003
  4. RSB
    Replies:
    6
    Views:
    7,671
    Karim
    May 19, 2004
  5. z. f.
    Replies:
    4
    Views:
    1,351
    z. f.
    Jun 23, 2004
Loading...

Share This Page