Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0 ASP.NET4.0
after bounding gridview with databse.
added added new column

How to code on that Button_Click ??
Posted 8-May-13 8:31am
Edited 8-May-13 9: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"&gt;
                      <asp:boundfield datafield="diarycontent" headertext="diarycontent">
                          SortExpression="diarycontent" /&gt;
                      <asp:boundfield datafield="diarypass" headertext="diarypass">
                          SortExpression="diarypass" /&gt;
                      <asp:boundfield datafield="diarydate" headertext="diarydate">
                          SortExpression="diarydate" /&gt;
                      <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" /&gt;

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

and its not working.Frown | :(
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 OriginalGriff 475
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 290
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210

Advertise | Privacy | Mobile
Web04 | 2.8.150331.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