Solved

gridview reference command field in code

Posted on 2006-06-30
2
574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

627 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