Solved

gridview reference command field in code

Posted on 2006-06-30
2
570 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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