Link to home
Start Free TrialLog in
Avatar of Gezna
Gezna

asked on

gridview reference command field in code

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>
ASKER CERTIFIED SOLUTION
Avatar of Hamed Zaghaghi
Hamed Zaghaghi
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deanvanrooyen
deanvanrooyen

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")