Click here to Skip to main content
13,054,018 members (73,973 online)
Rate this:
Please Sign up or sign in to vote.
See more:
after bounding gridview with databse.
added added new column

How to code on that Button_Click ??
Posted 8-May-13 7:31am
Updated 8-May-13 8:05am
Tadit Dash 8-May-13 13:56pm
Is this a DataGrid or GridView ?
praveenknoha 8-May-13 14:01pm
am sorry thats gridview ..
Tadit Dash 8-May-13 14:20pm
Ok, check my answer...
And if it is helpful, mark as answer and upvote.
praveenknoha 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 8-May-13 22:31pm
onrowcommand="MyGridView_RowCommand" Where to place this ?
Tadit Dash 9-May-13 1:34am
Problem solved or still it is not working ?
praveenknoha 9-May-13 9:48am
Its still persistent u can see my code snippet .. Its not working on click its making postback..
Tadit Dash 9-May-13 9:59am
Ok. Will take a look and let you know...
praveenknoha 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 11-May-13 2:19am
The problem is in markup command name is "Select", but in code it is "SELECT". Make them same.
praveenknoha 11-May-13 12:26pm
Thanks a lot ..
Tadit Dash 11-May-13 12:41pm
Most welcome buddy... :)
praveenknoha 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2017
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