Datagrid Buttom Column

Discussion in 'ASP .Net' started by Joana, Mar 3, 2005.

  1. Joana

    Joana Guest

    How do I make my ButtonColumn(In my DataGrid) to ResponseRedirect to another
    aspx.page when the user click on the button. I also want send with a id for
    the row.

    For eksample:
    ******************************************************************

    Private Sub DataGrid_kurs_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    DataGrid_kurs.SelectedIndexChanged
    Dim strKurs As String

    strKurs = DataGrid_kurs.SelectedItem.Cells(0).Text

    Response.Redirect("kurstilfelle.aspx?kurs=" + strKurs)

    End Sub

    ******************************************

    Is this the right plase to do it and how do make it work? Nothing happens
    when I click on the button.

    /Newbeginner :)
    Joana, Mar 3, 2005
    #1
    1. Advertising

  2. you need to use the Datagrids built in OnItemCommand and the
    DataGridCommandEventArgs in the Sub

    ..aspx

    <asp:DataGrid id=DataGrid_kurs runat=server
    OnItemCommand="DataGrid_kurs_OnItemCommand" AutogenerateColumns="true"/>

    ..vb (in the code)

    public sub DataGrid_kurs_OnItemCommand(sender As System.Object, e As
    System.DataGridCommandEventArgs)
    string strKurs = e.Item.Cells(0).Text 'where cell 0 has the id
    Response.Redirect("kurstilfelle.aspx?kurs=" + strKurs)
    End Sub

    Hope that clears things up


    "Joana" <johanna[invalid]> wrote in message
    news:...
    > How do I make my ButtonColumn(In my DataGrid) to ResponseRedirect to
    > another aspx.page when the user click on the button. I also want send
    > with a id for the row.
    >
    > For eksample:
    > ******************************************************************
    >
    > Private Sub DataGrid_kurs_SelectedIndexChanged(ByVal sender As
    > System.Object, ByVal e As System.EventArgs) Handles
    > DataGrid_kurs.SelectedIndexChanged
    > Dim strKurs As String
    >
    > strKurs = DataGrid_kurs.SelectedItem.Cells(0).Text
    >
    > Response.Redirect("kurstilfelle.aspx?kurs=" + strKurs)
    >
    > End Sub
    >
    > ******************************************
    >
    > Is this the right plase to do it and how do make it work? Nothing happens
    > when I click on the button.
    >
    > /Newbeginner :)
    >
    >
    Grant Merwitz, Mar 3, 2005
    #2
    1. Advertising

  3. Hi,

    If you want to use a button column, then you 've to write the eventhadler
    for the button column you crfeated, separately.

    Beofre that modify your .aspx source file like this, ( You have to include
    OnItemCommand ).


    <asp:DataGrid id="DgDetails" style="Z-INDEX: 103; LEFT: 64px; POSITION:
    absolute; TOP: 168px"
    runat="server" Width="784px" Height="120px" BorderColor="#3366CC"
    BorderWidth="1px" BackColor="White"
    BorderStyle="None" CellPadding="4" OnItemCommand="DgDetails_ItemCommand">
    <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99"
    BackColor="#009999"></SelectedItemStyle>
    <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF"
    BackColor="#003399"></HeaderStyle>
    <Columns>
    <asp:ButtonColumn Text="Select" ButtonType="PushButton"
    CommandName="Select" DataTextField="DNo"></asp:ButtonColumn>
    </Columns>
    </asp:DataGrid>

    You have to specify the index filed in "DataTextField" of <asp:ButtonColumn>
    node.

    In your code behind file...create a eventhandler as follows


    void DgDetails_ItemCommand(Object sender, DataGridCommandEventArgs e)
    {
    Response.Write(e.Item.ItemIndex.ToString());

    }

    e.Item.ItemIndex will have the value you need.

    Cheers,

    Jerome. M

    "Joana" wrote:

    > How do I make my ButtonColumn(In my DataGrid) to ResponseRedirect to another
    > aspx.page when the user click on the button. I also want send with a id for
    > the row.
    >
    > For eksample:
    > ******************************************************************
    >
    > Private Sub DataGrid_kurs_SelectedIndexChanged(ByVal sender As
    > System.Object, ByVal e As System.EventArgs) Handles
    > DataGrid_kurs.SelectedIndexChanged
    > Dim strKurs As String
    >
    > strKurs = DataGrid_kurs.SelectedItem.Cells(0).Text
    >
    > Response.Redirect("kurstilfelle.aspx?kurs=" + strKurs)
    >
    > End Sub
    >
    > ******************************************
    >
    > Is this the right plase to do it and how do make it work? Nothing happens
    > when I click on the button.
    >
    > /Newbeginner :)
    >
    >
    >
    =?Utf-8?B?RG90TmV0SmVyb21l?=, Mar 3, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hammond
    Replies:
    1
    Views:
    3,599
    bruce barker
    Nov 26, 2003
  2. Daniel Nielsen
    Replies:
    1
    Views:
    370
    Daniel Nielsen
    Apr 15, 2006
  3. Teresa
    Replies:
    1
    Views:
    295
    Andrew Thompson
    Oct 10, 2006
  4. John Carson

    Open a formView on buttom Clicked

    John Carson, Apr 29, 2006, in forum: C++
    Replies:
    1
    Views:
    399
    Daniel
    Apr 29, 2006
  5. George

    Prevent "Back" Buttom in Browser

    George, Jul 6, 2005, in forum: ASP General
    Replies:
    6
    Views:
    150
    Aaron Bertrand [SQL Server MVP]
    Jul 7, 2005
Loading...

Share This Page