473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
Jun 14 '07 #1
5 4023
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
Jun 14 '07 #2
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" <sh******@online.excite.comwrote in message
news:0A**********************************@microsof t.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

Jun 14 '07 #3
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
Jun 14 '07 #4
"LamSoft" <[nospam]la*****@lamsoft.netwrote in message
news:eE***************@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

Jun 14 '07 #5
Thank you you guys!!

It works for me now.
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:O7****************@TK2MSFTNGP04.phx.gbl...
"LamSoft" <[nospam]la*****@lamsoft.netwrote in message
news:eE***************@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

Jun 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lanem | last post by:
I have a gridview. One of the columns is a buttonfield. I use the datatextfield property of buttonfield to show my bound value as a hyperlink in each buttonfield cell. I then want to get that...
0
by: Ruy Castelli | last post by:
Hello, I'm trying to collect information from a GridView. Basically, the user clicks on a buttonfield (which is a link button) and then I need to get the information displayed on the gridview...
1
by: K B | last post by:
I would like to create a gridview as below: Project Name 1-1 1-2 1-3 1-4 1-5 1-6 Project 1 BLUE BLUE BLUE BLUE GREEN GREEN more projects I would like to fill the...
1
by: moni | last post by:
Hi, I was hoping to know how I could get the text value of a gridview row. My code is this way: <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"...
1
by: Dinu | last post by:
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: ...
4
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi I am pretty new to asp.net gridviews. I need to get the text in one column to scroll, I have little screen space and one column is normally empty, but is sometimes quite long. Has...
0
by: S_K | last post by:
Hi, I have an editible GridView that I can read the contents of each cell of the edit row as follows: int iEditIndex = GridView2.EditIndex; string strName = GridView2.Rows.Cells.Text; This...
4
by: foolmelon | last post by:
Before AJAX, we were able to focus a cell in a gridview during a fullpage postback. After putting the gridview inside an UpdatePanel, we cannot focus a cell in this gridview anymore. Does anybody...
2
by: cday119 | last post by:
Hey Everyone, I have a SqlDataSource hooked into a gridview. In the database I have a boolean property. It shows up in the gridview as true but I want to say something else. What is the best...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.