If there are a few Select buttons in a datagrid, is there a way to
distinguish in code which button was clicked?
Thanks. 5 6527
Do you mean that there is a select button for each row, or do you have
multiple select buttons for each row? If the latter, then why do you have
multiple select buttons for one row? If the former then you can determine
which select button was clicked by the SelectedIndex value, e.g.
'This is the method that handles the SelectedIndexChanged event of the
datagrid
Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
Dim iRowIndex As Integer = CType(sender, DataGrid).SelectedIndex
End Sub
--
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Vik" wrote: If there are a few Select buttons in a datagrid, is there a way to distinguish in code which button was clicked?
Thanks.
I want to have multiple select buttons in each row to perform different
actions on the row.
Vik
"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:8B**********************************@microsof t.com... Do you mean that there is a select button for each row, or do you have multiple select buttons for each row? If the latter, then why do you have multiple select buttons for one row? If the former then you can determine which select button was clicked by the SelectedIndex value, e.g.
'This is the method that handles the SelectedIndexChanged event of the datagrid Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged Dim iRowIndex As Integer = CType(sender, DataGrid).SelectedIndex End Sub -- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Vik" wrote:
If there are a few Select buttons in a datagrid, is there a way to distinguish in code which button was clicked?
Thanks.
You can use the CommandName parameter of the ButtonColumn control to be able
to determine the type of action that the user wish to perform on the record,
e.g.:
<asp:DataGrid ID="DataGrid1" Runat="server">
<Columns>
<asp:ButtonColumn DataTextField="Field1" CommandName="Select"
ButtonType="PushButton"></asp:ButtonColumn>
<asp:ButtonColumn Text="Delete Row" CommandName="Delete"
ButtonType="PushButton"></asp:ButtonColumn>
<asp:ButtonColumn Text="Duplicate Row" CommandName="Duplicate"
ButtonType="PushButton"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
And in handling the ItemCommand event of the datagrid, you would write code
similar to this:
private void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
{
switch (e.CommandName.ToString ())
{
case "Select":
//selection code
break;
case "Duplicate":
//do Duplicate code
break;
case "Delete":
//delete code
break;
}
}
--
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Vik" wrote: I want to have multiple select buttons in each row to perform different actions on the row.
Vik
"Phillip Williams" <Ph**************@webswapp.com> wrote in message news:8B**********************************@microsof t.com... Do you mean that there is a select button for each row, or do you have multiple select buttons for each row? If the latter, then why do you have multiple select buttons for one row? If the former then you can determine which select button was clicked by the SelectedIndex value, e.g.
'This is the method that handles the SelectedIndexChanged event of the datagrid Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged Dim iRowIndex As Integer = CType(sender, DataGrid).SelectedIndex End Sub -- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Vik" wrote:
If there are a few Select buttons in a datagrid, is there a way to distinguish in code which button was clicked?
Thanks.
Thanks.
Vik
"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:4F**********************************@microsof t.com... You can use the CommandName parameter of the ButtonColumn control to be able to determine the type of action that the user wish to perform on the record, e.g.:
<asp:DataGrid ID="DataGrid1" Runat="server"> <Columns> <asp:ButtonColumn DataTextField="Field1" CommandName="Select" ButtonType="PushButton"></asp:ButtonColumn> <asp:ButtonColumn Text="Delete Row" CommandName="Delete" ButtonType="PushButton"></asp:ButtonColumn> <asp:ButtonColumn Text="Duplicate Row" CommandName="Duplicate" ButtonType="PushButton"></asp:ButtonColumn> </Columns> </asp:DataGrid>
And in handling the ItemCommand event of the datagrid, you would write code similar to this:
private void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e) { switch (e.CommandName.ToString ()) { case "Select": //selection code break; case "Duplicate": //do Duplicate code break; case "Delete": //delete code break; }
} -- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Vik" wrote:
I want to have multiple select buttons in each row to perform different actions on the row.
Vik
"Phillip Williams" <Ph**************@webswapp.com> wrote in message news:8B**********************************@microsof t.com... > Do you mean that there is a select button for each row, or do you have > multiple select buttons for each row? If the latter, then why do you > have > multiple select buttons for one row? If the former then you can > determine > which select button was clicked by the SelectedIndex value, e.g. > > 'This is the method that handles the SelectedIndexChanged event of the > datagrid > Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As > System.Object, > ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged > Dim iRowIndex As Integer = CType(sender, DataGrid).SelectedIndex > End Sub > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Vik" wrote: > >> >> If there are a few Select buttons in a datagrid, is there a way to >> distinguish in code which button was clicked? >> >> Thanks. >> >> >>
each button is associated with an id, examine that id to determine what
button fired.
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------
"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:8B**********************************@microsof t.com... Do you mean that there is a select button for each row, or do you have multiple select buttons for each row? If the latter, then why do you have multiple select buttons for one row? If the former then you can determine which select button was clicked by the SelectedIndex value, e.g.
'This is the method that handles the SelectedIndexChanged event of the datagrid Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged Dim iRowIndex As Integer = CType(sender, DataGrid).SelectedIndex End Sub -- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Vik" wrote:
If there are a few Select buttons in a datagrid, is there a way to distinguish in code which button was clicked?
Thanks.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jon |
last post by:
Hello,
I have a datagrid and the data in it is dynamically created at runtime...
For iCounter = 0 To dataset.Tables(0).Columns.Count - 1
Dim objbc As New BoundColumn()
With objbc
.DataField...
|
by: Mike |
last post by:
I've seen buttons for each row on a datagrid, but does anyone know how i
could create 3 buttons at the bottom of my datagrid?
(within the datagrid itself)
thanks in advance
|
by: Jay |
last post by:
I noticed somewhere on the net that a post mentioned that there was a bug in
the datagrid, radio buttons and a repeater. Something about the radio
buttons are not mutually exclusive. (will this be...
|
by: Jay |
last post by:
I need to validate 21 sets of radio buttons before submission to the server
for calculation and storage. Is it best to validate on the client side
using javascript or to validate on the server...
|
by: Steve Kallal |
last post by:
I have a DataGrid with an EditCommandColumn column set to a type of PushButton. I want to set set CssClass on these buttons and cannot without using code-behind code on the ItemDataBound event. The...
|
by: pmud |
last post by:
Hi,
I have an ASP.NET application using C# code. I am using a datagrid to
display records from a database based on a user input, i.e a user enters a
compnay name in text box & when he clicks a...
|
by: CharlesA |
last post by:
Hi folks,
I really need help with the following scenario,
I'm going to describe as well as a I can what the setup is and what I can't
understand
I'm using the framework 1.1 using ASP.net with...
|
by: mapfax |
last post by:
I have 2 select button columns in my webform datagrid with each button's property set to the 'select' command name. How can I determine the column index selected for each of the buttons so that I...
|
by: Wan |
last post by:
Hi,
I have a test project which contains two simple forms - 1st form
contains datagrid and couple of buttons. First button to populate the
grid with Northwind.Customers records and show 3...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
| |