How to get gridview selected row text

D

Dinu

hi

i am having a gridview in aspx page and a usercontrol in master page
of that page

now what i want is selected row text to be displayed in usercontrol

i wrote code as follows:

Protected Sub gvwServices_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles gvwServices.SelectedIndexChanged
Me.Master.SetStatusText =
gvwServices.SelectedRow.Cells(0).Text
End Sub

here setstatus is the property of master page thats sets selected row
text to usercontrol

please help me in this regard

Thanks
 
B

Brian

I'm not quite sure if this is what you are after but:

internal void Grid_ViewCommand(Object sender, DataGridCommandEventArgs e)
{
TableCell itemCell = e.Item.Cells[1];
string item = itemCell.Text;
}

With a Grid, I typically put a button as the first column - called "View".
Clicking this button fires this event where I can retrieve the second cell
of the row (the first cell contains the button) that was selected and then
extract the text from. I suspect you need this same thing but on the
Index_Change event...

My Grid definition looks like this:
<asp:DataGrid ID="dataGrid1" runat="server" DataSourceID="XmlDataSource1"
Width="274px" AutoGenerateColumns="False" OnItemCommand="Grid_ViewCommand" >
<HeaderStyle BackColor="#00AAAA">
</HeaderStyle>
<Columns>
<asp:ButtonColumn
HeaderText="View"
ButtonType="PushButton"
Text="View"
CommandName="ViewItem" />

<asp:BoundColumn
HeaderText="Category Name"
DataField="name"/>
</Columns>
</asp:DataGrid>


-brian
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top