Solved

gridview reference command field in code

Posted on 2006-06-30
2
567 Views
Last Modified: 2008-01-09
Hi,

For the gridview in 2.0 can someone please tell me how to reference the below <asp:commandfield> in the code behind? I can get the whole column (gvProject.columns(0)), but not each individual control per row.

Should be something like gvProject.rows(index).findcontrol(id) , but there is no id for this control an none can be assigned.

Anyone?

<asp:GridView  onrowupdating="gvProject_RowUpdating"  ID="gvProject"  runat="server" AllowSorting="True" DataSourceID="ObjectDataSourceProject"  ForeColor="White" GridLines="None" AutoGenerateColumns="False" AllowPaging="True" Width="100%" AlternatingRowStyle-BorderStyle="None" AlternatingRowStyle-BorderColor="White" BorderStyle="None" BorderColor="White" EditRowStyle-BorderStyle="None" EditRowStyle-BorderColor="White" EmptyDataRowStyle-BorderStyle="None" EmptyDataRowStyle-BorderColor="White" FooterStyle-BorderStyle="None" FooterStyle-BorderColor="White" HeaderStyle-BorderStyle="None" HeaderStyle-BorderColor="White" PagerStyle-BorderStyle="None" PagerStyle-BorderColor="White" RowStyle-BorderStyle="None" RowStyle-BorderColor="White" SelectedRowStyle-BorderStyle="None" SelectedRowStyle-BorderColor="White">
                       
                    <Columns >             
                                         
                     <asp:CommandField  buttontype="Image" ValidationGroup="UpdateGroup" ShowEditButton="True" CancelImageUrl=".\Images\Plus.gif" EditImageUrl=".\Images\Plus.gif" UpdateImageUrl=".\Images\Plus.gif"  >
                       <ItemStyle VerticalAlign="Top" Height="20px"   />
                   </asp:CommandField>
0
Comment
Question by:Gezna
2 Comments
 
LVL 9

Accepted Solution

by:
zaghaghi earned 500 total points
ID: 17019698
handle the RowDataBind event

and use this for all rows
e.Row.Cells[i].Text for text or
e.Row.Cells[i].Controls[i] for controls in that cell

0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17020579
use above or

gvProject.Rows[gvProject.SelectedIndex].Cells[x]   //x is buttonindex

or use template field in the columns -  more flexibility
               <asp:TemplateField>
                     <ItemTemplate>
                          <asp:Button ID="itemButton" runat="server" CommandName="ButtonClick" Text="Click" />
                     </ItemTemplate>
                </asp:TemplateField>

then handle it in the rowcommand eventhandler
        .....
        <asp:GridView ID="GridView1" runat="server"  OnRowCommand="GridView1_RowCommand" .....

    public void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "ButtonClick")
        {
            this.TextBox1.Text = "ButtonClick";
        }

    }


by using templated field you can use this sort of thing
gvProject.rows(index).findcontrol("itemButton")

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending E-mail ASP.Net 3 57
ASP.Net Session State alternatives 3 61
Adjust the position 3 50
Help with C#, MVC, razor. 6 23
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now