HighTechTalks DotNet Forums  

Multiple Select commands

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss Multiple Select commands in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
David C
 
Posts: n/a

Default Multiple Select commands - 06-29-2009 , 03:44 PM






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

Reply With Quote
  #2  
Old   
Alexey Smirnov
 
Posts: n/a

Default Re: Multiple Select commands - 07-02-2009 , 09:01 AM






On Jun 29, 10:44*pm, "David C" <dlch... (AT) lifetimeinc (DOT) com> wrote:
Quote:
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 todo 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
Hi David,

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" /
Quote:
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

Reply With Quote
  #3  
Old   
David C
 
Posts: n/a

Default Re: Multiple Select commands - 07-02-2009 , 01:34 PM



Yes, that helps. Thank you so much.
"Alexey Smirnov" <alexey.smirnov (AT) gmail (DOT) com> wrote

On Jun 29, 10:44 pm, "David C" <dlch... (AT) lifetimeinc (DOT) com> wrote:
Quote:
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
Hi David,

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" /
Quote:
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

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.