Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get a text from a specified cell in the gridview?

Reply
Thread Tools

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

 
 
LamSoft
Guest
Posts: n/a
 
      06-14-2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2l2YSBN?=
Guest
Posts: n/a
 
      06-14-2007
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
>
>
>

 
Reply With Quote
 
 
 
 
LamSoft
Guest
Posts: n/a
 
      06-14-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?TWFyYyBXb29sZnNvbg==?=
Guest
Posts: n/a
 
      06-14-2007
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
>
>
>

 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      06-14-2007
"LamSoft" <[nospam](E-Mail Removed)> wrote in message
news:eEJ%(E-Mail Removed)...

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

 
Reply With Quote
 
LamSoft
Guest
Posts: n/a
 
      06-14-2007
Thank you you guys!!

It works for me now.
"Mark Rae" <(E-Mail Removed)> wrote in message
news:O7bA%(E-Mail Removed)...
> "LamSoft" <[nospam](E-Mail Removed)> wrote in message
> news:eEJ%(E-Mail Removed)...
>
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Can't get table cell width with text field to get smaller John Dalberg HTML 4 10-18-2006 03:00 PM
How to set and highlight text in JTable cell on selection and/or invoke cell editor directly. news.rcn.com Java 1 07-12-2004 10:22 PM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
multilink cell phones multilinking shotgun 2 cell phones Calvin Cisco 1 11-07-2003 02:20 PM



Advertisments