button control to get grid view data

Last post 05-09-2008 9:33 AM by ecbruck. 5 replies.

Sort Posts:

  • button control to get grid view data

    05-09-2008, 8:55 AM
    • Loading...
    • EF1978
    • Joined on 05-01-2008, 10:58 AM
    • Posts 15

    Hi,

    I have two columns - ref, description in a datagrid that has a datasource and returns a row with a reference and a description and I have a button column so that when cicked returns the ref and description into a label - works great. (I did this for testing purposes to see that I can get the data required)....read on.

    Now I have a web button control (btnGetRef) that when i press I want to get the ref column data and assign it to a variable for later use.

    I have tried using the function I created - "DispayBoundColumnValues", but when I enter it into the Button event handler it required a parameter and I'm not sure what.

    Can anyone please help????

    datagrid code:

    <asp:DataGrid runat="server" id="GridViewCables" AutoGenerateColumns="False"

    OnItemCommand="DisplayBoundColumnValues"

    DataSourceID="ODSNoOfCables" CellPadding="4" ForeColor="#333333" GridLines="None">

    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

    <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />

    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />

    <AlternatingItemStyle BackColor="White" />

    <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />

    <Columns>

    <asp:ButtonColumn Text="Click Me" HeaderText="Click" />

    <asp:BoundColumn DataField="ref" HeaderText="ref" />

    <asp:BoundColumn DataField="cable_no" HeaderText="description" />

    </Columns>

    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

    </asp:DataGrid>

     

    vb code:

    Sub DisplayBoundColumnValues(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

    Dim bc1 As String = e.Item.Cells(1).Text
    Dim bc2 As String = e.Item.Cells(2).Text

    lblBCValues.Text = bc2

    End Sub

    button event handler:

     

    Protected Sub btnGetRef(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click

    DisplayBoundColumnValues()

    End Sub

  • Re: button control to get grid view data

    05-09-2008, 9:00 AM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 2:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator
      TrustedFriends-MVPs

    You've created DisplayBoundColumnValues as an event handler instead of a simple Sub. Try removing the parameters from the signature.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: button control to get grid view data

    05-09-2008, 9:12 AM
    • Loading...
    • EF1978
    • Joined on 05-01-2008, 10:58 AM
    • Posts 15

    ok am new to vb, do you mind ellaborating?

    Thanks

  • Re: button control to get grid view data

    05-09-2008, 9:18 AM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 2:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator
      TrustedFriends-MVPs

    Sub DisplayBoundColumnValues()

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
  • Re: button control to get grid view data

    05-09-2008, 9:29 AM
    • Loading...
    • EF1978
    • Joined on 05-01-2008, 10:58 AM
    • Posts 15

    Ok but I need the ByVal e As DataGridCommandEventArgs.

  • Re: button control to get grid view data

    05-09-2008, 9:33 AM
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 2:39 PM
    • Des Moines, IA
    • Posts 5,743
    • Moderator
      TrustedFriends-MVPs

    Ok, then you need to change this back to an event handler and set the Handles clause for the proper event. Then, you no longer will use the Button.Click event and instead will let the Button raise your other event. You should also qualify your Button command calls by setting the CommandName property as well.

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

    protected void Post_Answered(object sender, EventArgs e) { if (this.MarkAsAnswered != null) { this.MarkAsAnswered(this, EventArgs.Empty); } }
Page 1 of 1 (6 items)