Click here to Skip to main content
11,812,712 members (73,248 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# C#4.0 ASP.NET4
after bounding gridview with databse.
added added new column

How to code on that Button_Click ??
Posted 8-May-13 7:31am
Edited 8-May-13 8:05am
Tadit Dash at 8-May-13 13:56pm
Is this a DataGrid or GridView ?
praveenknoha at 8-May-13 14:01pm
am sorry thats gridview ..
Tadit Dash at 8-May-13 14:20pm
Ok, check my answer...
And if it is helpful, mark as answer and upvote.
praveenknoha at 8-May-13 22:21pm
Can you tell me HOW can i pick that selected tuple any value (i.e column value) so that i can store that in session??
praveenknoha at 8-May-13 22:31pm
onrowcommand="MyGridView_RowCommand" Where to place this ?
Tadit Dash at 9-May-13 1:34am
Problem solved or still it is not working ?
praveenknoha at 9-May-13 9:48am
Its still persistent u can see my code snippet .. Its not working on click its making postback..
Tadit Dash at 9-May-13 9:59am
Ok. Will take a look and let you know...
praveenknoha at 10-May-13 0:38am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The GridView.RowCommand Event[^] will handle the button click.

You need to add one attribute onrowcommand="MyGridView_RowCommand" inside GridView MarkUp.

And define the Event in Code Behind as follows.
void MyGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
        // Do whatever you want to do.
Refer the MSDN link given above to know more and see the implementations.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

here is my markup

<asp:gridview id="GridView1" runat="server" allowpaging="True" xmlns:asp="#unknown">
                     AutoGenerateColumns="False" DataKeyNames="op" DataSourceID="SqlDataSource1"
                     style="z-index: 1; left: 276px;font-size:24px; top: 321px; position: absolute; height: 131px; width: 717px"
                     ForeColor="White" onrowcommand="GridView1_RowCommand">
                         <asp:boundfield datafield="diarycontent" headertext="diarycontent">
                             SortExpression="diarycontent" />
                         <asp:boundfield datafield="diarypass" headertext="diarypass">
                             SortExpression="diarypass" />
                         <asp:boundfield datafield="diarydate" headertext="diarydate">
                             SortExpression="diarydate" />
                         <asp:boundfield datafield="opp" headertext="page number" sortexpression="opp" />
                         <asp:buttonfield buttontype="Button" commandname="Select">
                             HeaderText="view diary page" ShowHeader="True" Text="View Diary Page" />

and cs code
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
       if (e.CommandName == "SELECT")

and its not working.:(
Tadit Dash at 11-May-13 2:19am
The problem is in markup command name is "Select", but in code it is "SELECT". Make them same.
praveenknoha at 11-May-13 12:26pm
Thanks a lot ..
Tadit Dash at 11-May-13 12:41pm
Most welcome buddy... :)
praveenknoha at 13-May-13 1:27am
Hey tadit one more question..
How can i pick particular value of a column on which button click is fired ..?
Tadit Dash at 13-May-13 2:46am
Take a look at the answer getting values of cells in rowcommand in gridview to know how to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Abhinav S 205
1 CHill60 180
2 KrunalRohit 169
3 Palash Mondal_ 140
0 OriginalGriff 3,877
1 KrunalRohit 2,496
2 CPallini 2,240
3 Maciej Los 2,205
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100