473,800 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 < gridSearchResul t.Rows.Count; i++)
{
CheckBox cb =
(CheckBox)gridS earchResult.Row s[i].FindControl("c heckBox_-1");
if (cb.Checked)
{
// get the value of the row in second column
// how to get it?
}
}

Thanks
Jun 14 '07 #1
5 4048
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 < gridSearchResul t.Rows.Count; i++)
{
CheckBox cb =
(CheckBox)gridS earchResult.Row s[i].FindControl("c heckBox_-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="gridSearchR esult" runat="server" CellPadding="4"
ForeColor="#333 333" GridLines="None " AutoGenerateCol umns="false">
<FooterStyle BackColor="#5D7 B9D" Font-Bold="True"
ForeColor="Whit e" />
<RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />
<EditRowStyle BackColor="#999 999" />
<SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True"
ForeColor="#333 333" />
<PagerStyle BackColor="#284 775" ForeColor="Whit e"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#5D7 B9D" Font-Bold="True"
ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />
<Columns>
<asp:TemplateFi eld HeaderText="Ena ble/Disable User Account">
<ItemTemplate >
<asp:CheckBox ID="checkBox_Di sable_User_Acco unt"
runat="server" />
</ItemTemplate>
</asp:TemplateFie ld>
<asp:HyperLinkF ield DataNavigateUrl Fields="User Name,Server
IP / HOST NAME"
DataNavigateUrl FormatString="e ditUserPwd.aspx ?username={0}&a mp;server={1}"
HeaderText="Edi t User" Text="Edit" />
<asp:BoundFie ld HeaderText="Use r Name" DataField="User
Name"/>
<asp:BoundFie ld HeaderText="Ser ver IP / HOST NAME"
DataField="Serv er IP / HOST NAME" />
</Columns>
</asp:GridView>

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

"Siva M" <sh******@onlin e.excite.comwro te in message
news:0A******** *************** ***********@mic rosoft.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 < gridSearchResul t.Rows.Count; i++)
{
CheckBox cb =
(CheckBox)grid SearchResult.Ro ws[i].FindControl("c heckBox_-1");
if (cb.Checked)
{
// get the value of the row in second column
// how to get it?
}
}

Thanks

Jun 14 '07 #3
How about:

gridSearchResul t.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 < gridSearchResul t.Rows.Count; i++)
{
CheckBox cb =
(CheckBox)gridS earchResult.Row s[i].FindControl("c heckBox_-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******** *******@TK2MSFT NGP02.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 gridSearchResul t)
{
if (((CheckBox)obj Row.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**@markNOSPA Mrae.netwrote in message
news:O7******** ********@TK2MSF TNGP04.phx.gbl. ..
"LamSoft" <[nospam]la*****@lamsoft .netwrote in message
news:eE******** *******@TK2MSFT NGP02.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 gridSearchResul t)
{
if (((CheckBox)obj Row.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
4948
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 text in the rowdatabound event. I can get it easily for each boundfield cell but not for the buttonfield. Please help. Thanks.
0
1395
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 cells populates some components on the screen. I'm trying the following: --------- Start of the code ---------
1
27505
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 cell with a solid color based on the value of the cell (e.g., documents that are complete (blue) or not complete (green). In effect have a solid bar indicator going across each row. I know how to color the cell based on the value, but not the click...
1
5484
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" BackColor="#8080FF" BorderColor="#0000C0" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Font- Size="Large" Height="192px" Width="243px"
1
5043
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: Protected Sub gvwServices_SelectedIndexChanged(ByVal sender As Object,
4
2451
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 anybody done this? Can I just put a Marquee into the column to acheive this? if so, how do I do that?
0
1274
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 works fine with the HTML of the cell set up as follows (note the readonly="True"):
4
5868
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 know if it is possible to make such focus? Thanks! Bill
2
1510
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 way to set if row.cell(0).text = "True" row.cell(0).text = "Finished" Kind of like drop down list has a value text mapping. Thanks
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.