How to get gridview selected row text

Discussion in 'ASP .Net' started by Dinu, Aug 7, 2007.

  1. Dinu

    Dinu Guest

    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
    Dinu, Aug 7, 2007
    #1
    1. Advertising

  2. Dinu

    Brian Guest

    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
    "Dinu" <> wrote in message
    news:...
    > 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
    >
    Brian, Aug 7, 2007
    #2
    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. H5N1
    Replies:
    0
    Views:
    2,698
  2. Replies:
    5
    Views:
    646
  3. Dan
    Replies:
    3
    Views:
    10,555
    Natheer sheriff
    May 30, 2009
  4. Want to add row under selected row of gridview

    , Feb 16, 2007, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    292
  5. Selected Row Only GridView Row Visible?

    , Oct 17, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    280
Loading...

Share This Page