2 Replies - 4085 Views - Last Post: 06 September 2012 - 07:11 PM Rate Topic: -----

#1 dbca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-September 12

RowCommand event button control GridView ItemTemplate in C# asp.net

Posted 06 September 2012 - 05:45 PM

Trying to create a functional rowcommand event.
The results of a database query produce button controls. I am trying to produce a RowCommand event that is able to perform some logic on the record the button control is referring to.
I was wondering how i could put data into the text attribute of labels.

Here is my asp.net code:

    <asp:GridView ID="QueryPaneResults" runat="server" AutoGenerateColumns="False" DataSourceID="QueryData" AllowPaging="True" >
	    <Columns>
            <asp:TemplateField SortExpression="OrgName" >
                <ItemTemplate>
                    <asp:Button ID="btnOrg" runat="server" Text='<%# Bind("OrgName") %>' CommandName="SelectionData" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" ></asp:Button> 
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="QueryData" runat="server" ConnectionString="<%$ ConnectionStrings:dbca %>" SelectCommand="SELECT * FROM [Organization]"></asp:SqlDataSource>



Next is my C# code

    protected void QueryPaneResults_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "SelectionData")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = QueryPaneResults.Rows[index];
        }
    }



This is the point where I am stuck. I cannot figure how to put the results into a variables.
I cannot get the RowCommand event to do anything.

Any help would be highly appreciated!!

Is This A Good Question/Topic? 0
  • +

Replies To: RowCommand event button control GridView ItemTemplate in C# asp.net

#2 dbca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-September 12

Re: RowCommand event button control GridView ItemTemplate in C# asp.net

Posted 06 September 2012 - 06:33 PM

I figured it out.
Just to let anybody know who reads this I was missing the OnRowCommand statement.
Was This Post Helpful? 0
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: RowCommand event button control GridView ItemTemplate in C# asp.net

Posted 06 September 2012 - 07:11 PM

Yep, you would definitely need that, glad you got it sorted out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1