Datagrid Buttom Column

J

Joana

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 :)
 
G

Grant Merwitz

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
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top