How to get gridview selected row text

  • Thread starter Thread starter Dinu
  • Start date Start date
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
 
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
 
Back
Top