How to get a text from a specified cell in the gridview?

Discussion in 'ASP .Net' started by LamSoft, Jun 14, 2007.

  1. LamSoft

    LamSoft Guest

    If there is a table(2x2) generated from the gridview as below

    checkbox-1 mytest-1 mytest-2
    checkbox-1 mytest-3 mytest-3

    I know how to check that two checkbox are checked or not, but how to get the
    value of other column at the same row while in the for-loop statement.

    for (int i = 0; i < gridSearchResult.Rows.Count; i++)
    {
    CheckBox cb =
    (CheckBox)gridSearchResult.Rows.FindControl("checkBox_-1");
    if (cb.Checked)
    {
    // get the value of the row in second column
    // how to get it?
    }
    }

    Thanks
     
    LamSoft, Jun 14, 2007
    #1
    1. Advertising

  2. What type of control is it? Label? If so, do the same FindControl() method
    passing the ID of the label.

    "LamSoft" wrote:

    > If there is a table(2x2) generated from the gridview as below
    >
    > checkbox-1 mytest-1 mytest-2
    > checkbox-1 mytest-3 mytest-3
    >
    > I know how to check that two checkbox are checked or not, but how to get the
    > value of other column at the same row while in the for-loop statement.
    >
    > for (int i = 0; i < gridSearchResult.Rows.Count; i++)
    > {
    > CheckBox cb =
    > (CheckBox)gridSearchResult.Rows.FindControl("checkBox_-1");
    > if (cb.Checked)
    > {
    > // get the value of the row in second column
    > // how to get it?
    > }
    > }
    >
    > Thanks
    >
    >
    >
     
    =?Utf-8?B?U2l2YSBN?=, Jun 14, 2007
    #2
    1. Advertising

  3. LamSoft

    LamSoft Guest

    Nothing, no ID attached to that cell
    The HTML code of that gridview is

    <asp:GridView ID="gridSearchResult" runat="server" CellPadding="4"
    ForeColor="#333333" GridLines="None" AutoGenerateColumns="false">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <EditRowStyle BackColor="#999999" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
    ForeColor="#333333" />
    <PagerStyle BackColor="#284775" ForeColor="White"
    HorizontalAlign="Center" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
    ForeColor="White" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
    <asp:TemplateField HeaderText="Enable/Disable User Account">
    <ItemTemplate>
    <asp:CheckBox ID="checkBox_Disable_User_Account"
    runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:HyperLinkField DataNavigateUrlFields="User Name,Server
    IP / HOST NAME"
    DataNavigateUrlFormatString="editUserPwd.aspx?username={0}&amp;server={1}"
    HeaderText="Edit User" Text="Edit" />
    <asp:BoundField HeaderText="User Name" DataField="User
    Name"/>
    <asp:BoundField HeaderText="Server IP / HOST NAME"
    DataField="Server IP / HOST NAME" />
    </Columns>
    </asp:GridView>

    I want to get the value of boundfield Server IP, thank you.

    "Siva M" <> wrote in message
    news:...
    > What type of control is it? Label? If so, do the same FindControl() method
    > passing the ID of the label.
    >
    > "LamSoft" wrote:
    >
    >> If there is a table(2x2) generated from the gridview as below
    >>
    >> checkbox-1 mytest-1 mytest-2
    >> checkbox-1 mytest-3 mytest-3
    >>
    >> I know how to check that two checkbox are checked or not, but how to get
    >> the
    >> value of other column at the same row while in the for-loop statement.
    >>
    >> for (int i = 0; i < gridSearchResult.Rows.Count; i++)
    >> {
    >> CheckBox cb =
    >> (CheckBox)gridSearchResult.Rows.FindControl("checkBox_-1");
    >> if (cb.Checked)
    >> {
    >> // get the value of the row in second column
    >> // how to get it?
    >> }
    >> }
    >>
    >> Thanks
    >>
    >>
    >>
     
    LamSoft, Jun 14, 2007
    #3
  4. How about:

    gridSearchResult.Rows.Cells[1].Text;

    Marc


    "LamSoft" wrote:

    > If there is a table(2x2) generated from the gridview as below
    >
    > checkbox-1 mytest-1 mytest-2
    > checkbox-1 mytest-3 mytest-3
    >
    > I know how to check that two checkbox are checked or not, but how to get the
    > value of other column at the same row while in the for-loop statement.
    >
    > for (int i = 0; i < gridSearchResult.Rows.Count; i++)
    > {
    > CheckBox cb =
    > (CheckBox)gridSearchResult.Rows.FindControl("checkBox_-1");
    > if (cb.Checked)
    > {
    > // get the value of the row in second column
    > // how to get it?
    > }
    > }
    >
    > Thanks
    >
    >
    >
     
    =?Utf-8?B?TWFyYyBXb29sZnNvbg==?=, Jun 14, 2007
    #4
  5. LamSoft

    Mark Rae Guest

    "LamSoft" <[nospam]> wrote in message
    news:eEJ%...

    I'm assuming that the second and third rows are just text i.e. not seperate
    controls...

    string strSecondColumn = String.Empty;
    foreach (GridViewRow objRow in gridSearchResult)
    {
    if (((CheckBox)objRow.FindControl("checkBox_-1")).Checked)
    {
    strSecondColumn = objRow.Cells[1].Text;
    }
    }


    --
    http://www.markrae.net
     
    Mark Rae, Jun 14, 2007
    #5
  6. LamSoft

    LamSoft Guest

    Thank you you guys!!

    It works for me now.
    "Mark Rae" <> wrote in message
    news:O7bA%...
    > "LamSoft" <[nospam]> wrote in message
    > news:eEJ%...
    >
    > I'm assuming that the second and third rows are just text i.e. not
    > seperate controls...
    >
    > string strSecondColumn = String.Empty;
    > foreach (GridViewRow objRow in gridSearchResult)
    > {
    > if (((CheckBox)objRow.FindControl("checkBox_-1")).Checked)
    > {
    > strSecondColumn = objRow.Cells[1].Text;
    > }
    > }
    >
    >
    > --
    > http://www.markrae.net
     
    LamSoft, Jun 14, 2007
    #6
    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. news.rcn.com
    Replies:
    1
    Views:
    9,680
    Chris Smith
    Jul 12, 2004
  2. James Irvine
    Replies:
    0
    Views:
    442
    James Irvine
    Jan 17, 2007
  3. mark4asp
    Replies:
    0
    Views:
    463
    mark4asp
    Jan 18, 2007
  4. John Dalberg
    Replies:
    4
    Views:
    787
  5. S_K
    Replies:
    1
    Views:
    3,648
    Yankee Imperialist Dog
    Jun 5, 2008
Loading...

Share This Page