|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Multiple Select commandsI have an asp.net GridView and I would like to have more than 1 "Select"
button that selects the current row. I want all of the Select links to do a PostBack to the current page and then do something based on the CommandArguement. Is that possible, and if so, what event do I use to check the command arguement? Thanks. David On Jun 29, 10:44 pm, "David C" <dlch***@lifetimeinc.com> wrote: Hi David,> I have an asp.net GridView and I would like to have more than 1 "Select" > button that selects the current row. I want all of the Select links to do a > PostBack to the current page and then do something based on the > CommandArguement. Is that possible, and if so, what event do I use to check > the command arguement? Thanks. > > David > > ----------------------------------------------------------------------------- > Our Peering Groups change > Visit :http://spacesst.com/peerin maybe you can use TemplateField for this. Here's little example <asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"> <Columns> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" /> <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" / > <asp:TemplateField HeaderText="Select"><ItemTemplate> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("CategoryID") %>' CommandName="Delete" runat="server"> Delete</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1"); l.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete this record " + DataBinder.Eval(e.Row.DataItem, "CategoryID") + "')"); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { // get the categoryID of the clicked row int categoryID = Convert.ToInt32(e.CommandArgument); // Delete the record DeleteRecordByID(categoryID); // Implement this on your own :) } } As you can see, you can put as many linkbuttons you need using TemplateField and get command using GridViewCommandEventArgs.CommandName Hope this helps Yes, that helps. Thank you so much.
Show quoteHide quote "Alexey Smirnov" <alexey.smir***@gmail.com> wrote in message Hi David,news:cbd00af3-5625-4aff-80d4-aab0b2ee2b75@b15g2000yqd.googlegroups.com... On Jun 29, 10:44 pm, "David C" <dlch***@lifetimeinc.com> wrote: > I have an asp.net GridView and I would like to have more than 1 "Select" > button that selects the current row. I want all of the Select links to do > a > PostBack to the current page and then do something based on the > CommandArguement. Is that possible, and if so, what event do I use to > check > the command arguement? Thanks. > > David > > ----------------------------------------------------------------------------- > Our Peering Groups change > Visit :http://spacesst.com/peerin maybe you can use TemplateField for this. Here's little example <asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"> <Columns> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" /> <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" / > <asp:TemplateField HeaderText="Select"><ItemTemplate> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("CategoryID") %>' CommandName="Delete" runat="server"> Delete</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1"); l.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete this record " + DataBinder.Eval(e.Row.DataItem, "CategoryID") + "')"); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { // get the categoryID of the clicked row int categoryID = Convert.ToInt32(e.CommandArgument); // Delete the record DeleteRecordByID(categoryID); // Implement this on your own :) } } As you can see, you can put as many linkbuttons you need using TemplateField and get command using GridViewCommandEventArgs.CommandName Hope this helps
Other interesting topics
Web Deployment Project - Publish?
Problem with AddHandler (New CommandEventHandler) under framework 2.0 Displaying a generated picture in MS Word Image does not fit correctly in a div frame Localization issue with master page. Boundfield display value How to get an https url when using Forms and Default login redirect C# / VB.NET code which takes a datetime in as parameter and returns a string How to write metainformation in asp.net dll Can't get started with this JavaScript |
|||||||||||||||||||||||