473,568 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I get the value of a column in a datagrid?

Hello. I have a datagird with textboxes on a column item template, I also
have 2 other columns that are hidden and I want to retrieve his value. But I
havent found how to do it.
Thanks very much in advance

This is the code that loops through all rows. find the textboxes controls

Private Sub btnguardarpland esarrollo_Click (ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles btnguardarpland esarrollo.Click

Page.Validate()

If Page.IsValid Then

Dim cont As Int32 = 0

Dim di As DataGridItem

For Each di In dgplandesarroll o.Items

Dim responsabilidad jefe As TextBox = New TextBox

responsabilidad jefe = CType(di.FindCo ntrol("jefe"), TextBox)

Dim responsabilidad dh As TextBox = New TextBox

responsabilidad dh = CType(di.FindCo ntrol("dh"), TextBox)

Dim responsabilidad colaborador As TextBox = New TextBox

responsabilidad colaborador = CType(di.FindCo ntrol("colabora dor"), TextBox)

Dim tempresa As TextBox = New TextBox

tempresa = CType(di.FindCo ntrol("tempresa "), TextBox)

Dim tcolaborador As TextBox = New TextBox

tcolaborador = CType(di.FindCo ntrol("tcolabor ador"), TextBox)

Dim id As Int32 = dgplandesarroll o.DataKeys.Item (cont)

Try

' Here I want to retrieve the values of second and third columns that are
hidden.

panelmensajes.V isible = True

lblmensajes.Tex t = "Usted ha ingresado correctamente el plan de desarrollo,
presione el boton siguiente para continuar con la retroalimentaci on al jefe
inmediato y las competencias pactadas"

Catch ex As Exception

panelmensajes.V isible = True

lblmensajes.Tex t = ex.Message

End Try

cont += 1

Next

End If

End Sub


This is my HTML datagrid

<asp:DataGrid id=dgplandesarr ollo runat="server" Visible="False"
Width="100%" AutoGenerateCol umns="False">
<ItemStyle CssClass="itemd g">
</ItemStyle>

<HeaderStyle Font-Size="Small" Font-Bold="True" CssClass="titul odg">
</HeaderStyle>

<Columns>
<asp:TemplateCo lumn HeaderText="Com petencia y Comportamiento" >
<ItemTemplate >
<P>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval (Container,
"DataItem.caden a") %>' Font-Bold="True" Font-Size="Small" ForeColor="Red" >
</asp:Label></P>
<TABLE class=letras id=Table3 borderColor=#00 0000 cellSpacing=0
borderColorDark =#ffffff cellPadding=1 width="100%" border=1>
<TR>
<TD class=titulodg colSpan=2><STRO NG><FONT size=1>PLAN DE DESARROLLO PARA
ESTE COMPORTAMIENTO</FONT></STRONG></TD></TR>
<TR>
<TD class=letras>Re sponsabilidad Jefe Inmediato
<asp:RequiredFi eldValidator id=RequiredFiel dValidator1 runat="server"
ErrorMessage="* " ControlToValida te="jefe"></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=jefe runat="server" Width="200px" CssClass="textb oxes"
Height="38px" TextMode="Multi Line"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabil idad Desarrollo Humano
<asp:RequiredFi eldValidator id=RequiredFiel dValidator2 runat="server"
ErrorMessage="* " ControlToValida te="dh"></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=dh runat="server" Width="200px" CssClass="textb oxes"
Height="30px" TextMode="Multi Line"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabil idad Colaborador
<asp:RequiredFi eldValidator id=RequiredFiel dValidator3 runat="server"
ErrorMessage="* "
ControlToValida te="colaborador "></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=colaborador runat="server" Width="200px"
CssClass="textb oxes" Height="38px"
TextMode="Multi Line"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Empresa
<asp:RequiredFi eldValidator id=RequiredFiel dValidator4 runat="server"
ErrorMessage="* "
ControlToValida te="tempresa"> </asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=tempresa runat="server" Width="78px"
CssClass="textb oxes"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Colaborador
<asp:RequiredFi eldValidator id=RequiredFiel dValidator5 runat="server"
ErrorMessage="* "
ControlToValida te="tcolaborado r"></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=tcolaborador runat="server" Width="78px"
CssClass="textb oxes"></asp:TextBox></TD></TR></TABLE>
<HR width="100%" color=red noShade SIZE=3>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:BoundColum n Visible="False" DataField="idCo mpetencia"
HeaderText="idC ompetencia"></asp:BoundColumn >
<asp:BoundColum n Visible="False" DataField="idco mportamiento"
HeaderText="idc omportamiento"> </asp:BoundColumn >
</Columns>
</asp:DataGrid
--

LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
Nov 19 '05 #1
1 2358
Hi Luis,

You can get the values by counting the cells and getting the Text property
of each.

Since you have three columns, you can get them like this:

Response.Write( "Second cell:" & di.Cells(1).Tex t &
"<br>")
Response.Write( "Third cell:" & di.Cells(2).Tex t &
"<br>")

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

"Luis Esteban Valencia" <lu*******@hace b.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hello. I have a datagird with textboxes on a column item template, I also
have 2 other columns that are hidden and I want to retrieve his value. But
I
havent found how to do it.
Thanks very much in advance

This is the code that loops through all rows. find the textboxes controls

Private Sub btnguardarpland esarrollo_Click (ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles btnguardarpland esarrollo.Click

Page.Validate()

If Page.IsValid Then

Dim cont As Int32 = 0

Dim di As DataGridItem

For Each di In dgplandesarroll o.Items

Dim responsabilidad jefe As TextBox = New TextBox

responsabilidad jefe = CType(di.FindCo ntrol("jefe"), TextBox)

Dim responsabilidad dh As TextBox = New TextBox

responsabilidad dh = CType(di.FindCo ntrol("dh"), TextBox)

Dim responsabilidad colaborador As TextBox = New TextBox

responsabilidad colaborador = CType(di.FindCo ntrol("colabora dor"), TextBox)

Dim tempresa As TextBox = New TextBox

tempresa = CType(di.FindCo ntrol("tempresa "), TextBox)

Dim tcolaborador As TextBox = New TextBox

tcolaborador = CType(di.FindCo ntrol("tcolabor ador"), TextBox)

Dim id As Int32 = dgplandesarroll o.DataKeys.Item (cont)

Try

' Here I want to retrieve the values of second and third columns that are
hidden.

panelmensajes.V isible = True

lblmensajes.Tex t = "Usted ha ingresado correctamente el plan de
desarrollo,
presione el boton siguiente para continuar con la retroalimentaci on al
jefe
inmediato y las competencias pactadas"

Catch ex As Exception

panelmensajes.V isible = True

lblmensajes.Tex t = ex.Message

End Try

cont += 1

Next

End If

End Sub


This is my HTML datagrid

<asp:DataGrid id=dgplandesarr ollo runat="server" Visible="False"
Width="100%" AutoGenerateCol umns="False">
<ItemStyle CssClass="itemd g">
</ItemStyle>

<HeaderStyle Font-Size="Small" Font-Bold="True" CssClass="titul odg">
</HeaderStyle>

<Columns>
<asp:TemplateCo lumn HeaderText="Com petencia y Comportamiento" >
<ItemTemplate >
<P>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval (Container,
"DataItem.caden a") %>' Font-Bold="True" Font-Size="Small" ForeColor="Red" >
</asp:Label></P>
<TABLE class=letras id=Table3 borderColor=#00 0000 cellSpacing=0
borderColorDark =#ffffff cellPadding=1 width="100%" border=1>
<TR>
<TD class=titulodg colSpan=2><STRO NG><FONT size=1>PLAN DE DESARROLLO PARA
ESTE COMPORTAMIENTO</FONT></STRONG></TD></TR>
<TR>
<TD class=letras>Re sponsabilidad Jefe Inmediato
<asp:RequiredFi eldValidator id=RequiredFiel dValidator1 runat="server"
ErrorMessage="* "
ControlToValida te="jefe"></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=jefe runat="server" Width="200px" CssClass="textb oxes"
Height="38px" TextMode="Multi Line"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabil idad Desarrollo Humano
<asp:RequiredFi eldValidator id=RequiredFiel dValidator2 runat="server"
ErrorMessage="* " ControlToValida te="dh"></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=dh runat="server" Width="200px" CssClass="textb oxes"
Height="30px" TextMode="Multi Line"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabil idad Colaborador
<asp:RequiredFi eldValidator id=RequiredFiel dValidator3 runat="server"
ErrorMessage="* "
ControlToValida te="colaborador "></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=colaborador runat="server" Width="200px"
CssClass="textb oxes" Height="38px"
TextMode="Multi Line"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Empresa
<asp:RequiredFi eldValidator id=RequiredFiel dValidator4 runat="server"
ErrorMessage="* "
ControlToValida te="tempresa"> </asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=tempresa runat="server" Width="78px"
CssClass="textb oxes"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Colaborador
<asp:RequiredFi eldValidator id=RequiredFiel dValidator5 runat="server"
ErrorMessage="* "
ControlToValida te="tcolaborado r"></asp:RequiredFie ldValidator></TD>
<TD>
<asp:TextBox id=tcolaborador runat="server" Width="78px"
CssClass="textb oxes"></asp:TextBox></TD></TR></TABLE>
<HR width="100%" color=red noShade SIZE=3>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:BoundColum n Visible="False" DataField="idCo mpetencia"
HeaderText="idC ompetencia"></asp:BoundColumn >
<asp:BoundColum n Visible="False" DataField="idco mportamiento"
HeaderText="idc omportamiento"> </asp:BoundColumn >
</Columns>
</asp:DataGrid
--

LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/


Nov 19 '05 #2

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

Similar topics

1
2719
by: Swadh | last post by:
Hi, I need urgent help on Windows Form datagrid. I have to Display a datagrid that has a textbox column and another one combo box column. I have two tables in my Access database as: Table 1: Columns: Part_ID, Descr Here Part_ID is Primary key. Table 2:
0
1568
by: Lalit Bhatia | last post by:
Hi, In Datagrid, while setting width of column through GridColumnStyles collection. width does not set to exact width that I am setting in my code. If I set width to 13, it is changed to 130 or if set to 208, it changes to 206. On changing width of column I am resizing the width of grid. I am using mouse down and mouse up events for this....
2
10560
by: Robert | last post by:
I'm sure this is a fairly basic question, but I've been looking all over the web for days for suggestions on how to do this. I've got a datagrid that's bound to a dataset on my form. It includes several columns, the last of which (with the header Quantity) contains int16 values. When a user selects a row, I would like to have a combobox on...
0
2639
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the CompanyName, ContactName, and ContactTitle columns from the Customers table in the Northwind database. Whenever the value of ContactTitle equals...
5
1811
by: Jason | last post by:
I've been trying to figure out a good way to do this but haven't had much luck, any input would be greatly appreciated. Basically, after a datagrid is sorted, how can I get the primary key value of the item selected by the user? That is, not the datagrid index 'location' of the item the user selected, but the value inside a column of this...
9
15004
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text returns a blank string. It seems to work ok for the other columns that are just regular datagrid columns, not hyperlink...
9
2071
by: Coleen | last post by:
Hi All :-) I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used: dt_stat_report_3b.Columns.Add(New DataColumn("Sum", GetType(Double), "sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg)")) where dt_stat_report_3b is my datatable, Sum is my column name and...
0
1923
by: Matt | last post by:
I derived my own custom class from the datagrid class. I overrode the ProcessCmdKey Function, like this, to catch the up and down arrow keys: ====== Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean Const WM_KEYDOWN As Integer = &H100
2
2118
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the first column can only be either "Text" or "Image", which is selcted in a dropdown list.
4
1597
by: simon | last post by:
hello, i am displaying a dataset in a datagrid, for one of the values being displayed it either comes back as a 1 or a 0, which is currently bound to a column in the datagrid what i'd like to do is that if the value equals 1, replace that value with a small icon image. if it equals 0 then have nothing display in that column. can this be...
0
7693
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...
0
7916
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. ...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
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...
0
5217
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.