Click here to Skip to main content
Rate this: bad
good
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
FIELD TYPE : BUTTON FIELD
BUTTON TYPE :BUTTON
COMMAND NAME :SELECT
 
How to code on that Button_Click ??
Posted 8-May-13 8:31am
Edited 8-May-13 9:05am
v3
Comments
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
   
thanks.
Rate this: bad
good
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)
{
    if(e.CommandName=="SELECT")
    {
        // Do whatever you want to do.
    }
}
Refer the MSDN link given above to know more and see the implementations.
Rate this: bad
good
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">
                      <columns>
                          <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" />
                      </asp:buttonfield></asp:boundfield></asp:boundfield></asp:boundfield></columns>
                  </asp:gridview>
 
and cs code
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       
        if (e.CommandName == "SELECT")
        {
            
            MessageBox.Show("hello");
        }
    }
 
and its not working.:(
  Permalink  
Comments
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 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2014
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