Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   How to get a text from a specified cell in the gridview? (http://www.velocityreviews.com/forums/t514478-how-to-get-a-text-from-a-specified-cell-in-the-gridview.html)

LamSoft 06-14-2007 07:46 AM

How to get a text from a specified cell in the gridview?
 
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[i].FindControl("checkBox_-1");
if (cb.Checked)
{
// get the value of the row in second column
// how to get it?
}
}

Thanks



=?Utf-8?B?U2l2YSBN?= 06-14-2007 08:00 AM

RE: How to get a text from a specified cell in the gridview?
 
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[i].FindControl("checkBox_-1");
> if (cb.Checked)
> {
> // get the value of the row in second column
> // how to get it?
> }
> }
>
> Thanks
>
>
>


LamSoft 06-14-2007 08:06 AM

Re: How to get a text from a specified cell in the gridview?
 
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?user name={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" <shiva_sm@online.excite.com> wrote in message
news:0A1CA5C8-C1A7-4671-AAB2-6EED1BE7271D@microsoft.com...
> 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[i].FindControl("checkBox_-1");
>> if (cb.Checked)
>> {
>> // get the value of the row in second column
>> // how to get it?
>> }
>> }
>>
>> Thanks
>>
>>
>>




=?Utf-8?B?TWFyYyBXb29sZnNvbg==?= 06-14-2007 08:07 AM

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

gridSearchResult.Rows[i].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[i].FindControl("checkBox_-1");
> if (cb.Checked)
> {
> // get the value of the row in second column
> // how to get it?
> }
> }
>
> Thanks
>
>
>


Mark Rae 06-14-2007 08:08 AM

Re: How to get a text from a specified cell in the gridview?
 
"LamSoft" <[nospam]lamsoft@lamsoft.net> wrote in message
news:eEJ%23xglrHHA.884@TK2MSFTNGP02.phx.gbl...

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 06-14-2007 08:25 AM

Re: How to get a text from a specified cell in the gridview?
 
Thank you you guys!!

It works for me now.
"Mark Rae" <mark@markNOSPAMrae.net> wrote in message
news:O7bA%23slrHHA.4180@TK2MSFTNGP04.phx.gbl...
> "LamSoft" <[nospam]lamsoft@lamsoft.net> wrote in message
> news:eEJ%23xglrHHA.884@TK2MSFTNGP02.phx.gbl...
>
> 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





All times are GMT. The time now is 02:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.