Solved

gridview reference command field in code

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

21 Experts available now in Live!

Get 1:1 Help Now