473,394 Members | 1,800 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,394 software developers and data experts.

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 btnguardarplandesarrollo_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnguardarplandesarrollo.Click

Page.Validate()

If Page.IsValid Then

Dim cont As Int32 = 0

Dim di As DataGridItem

For Each di In dgplandesarrollo.Items

Dim responsabilidadjefe As TextBox = New TextBox

responsabilidadjefe = CType(di.FindControl("jefe"), TextBox)

Dim responsabilidaddh As TextBox = New TextBox

responsabilidaddh = CType(di.FindControl("dh"), TextBox)

Dim responsabilidadcolaborador As TextBox = New TextBox

responsabilidadcolaborador = CType(di.FindControl("colaborador"), TextBox)

Dim tempresa As TextBox = New TextBox

tempresa = CType(di.FindControl("tempresa"), TextBox)

Dim tcolaborador As TextBox = New TextBox

tcolaborador = CType(di.FindControl("tcolaborador"), TextBox)

Dim id As Int32 = dgplandesarrollo.DataKeys.Item(cont)

Try

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

panelmensajes.Visible = True

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

Catch ex As Exception

panelmensajes.Visible = True

lblmensajes.Text = ex.Message

End Try

cont += 1

Next

End If

End Sub


This is my HTML datagrid

<asp:DataGrid id=dgplandesarrollo runat="server" Visible="False"
Width="100%" AutoGenerateColumns="False">
<ItemStyle CssClass="itemdg">
</ItemStyle>

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

<Columns>
<asp:TemplateColumn HeaderText="Competencia y Comportamiento">
<ItemTemplate>
<P>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.cadena") %>' Font-Bold="True" Font-Size="Small" ForeColor="Red">
</asp:Label></P>
<TABLE class=letras id=Table3 borderColor=#000000 cellSpacing=0
borderColorDark=#ffffff cellPadding=1 width="100%" border=1>
<TR>
<TD class=titulodg colSpan=2><STRONG><FONT size=1>PLAN DE DESARROLLO PARA
ESTE COMPORTAMIENTO</FONT></STRONG></TD></TR>
<TR>
<TD class=letras>Responsabilidad Jefe Inmediato
<asp:RequiredFieldValidator id=RequiredFieldValidator1 runat="server"
ErrorMessage="*" ControlToValidate="jefe"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=jefe runat="server" Width="200px" CssClass="textboxes"
Height="38px" TextMode="MultiLine"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabilidad Desarrollo Humano
<asp:RequiredFieldValidator id=RequiredFieldValidator2 runat="server"
ErrorMessage="*" ControlToValidate="dh"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=dh runat="server" Width="200px" CssClass="textboxes"
Height="30px" TextMode="MultiLine"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabilidad Colaborador
<asp:RequiredFieldValidator id=RequiredFieldValidator3 runat="server"
ErrorMessage="*"
ControlToValidate="colaborador"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=colaborador runat="server" Width="200px"
CssClass="textboxes" Height="38px"
TextMode="MultiLine"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Empresa
<asp:RequiredFieldValidator id=RequiredFieldValidator4 runat="server"
ErrorMessage="*"
ControlToValidate="tempresa"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=tempresa runat="server" Width="78px"
CssClass="textboxes"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Colaborador
<asp:RequiredFieldValidator id=RequiredFieldValidator5 runat="server"
ErrorMessage="*"
ControlToValidate="tcolaborador"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=tcolaborador runat="server" Width="78px"
CssClass="textboxes"></asp:TextBox></TD></TR></TABLE>
<HR width="100%" color=red noShade SIZE=3>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False" DataField="idCompetencia"
HeaderText="idCompetencia"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="idcomportamiento"
HeaderText="idcomportamiento"></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 2348
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).Text &
"<br>")
Response.Write("Third cell:" & di.Cells(2).Text &
"<br>")

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

"Luis Esteban Valencia" <lu*******@haceb.com> wrote in message
news:%2****************@TK2MSFTNGP14.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 btnguardarplandesarrollo_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnguardarplandesarrollo.Click

Page.Validate()

If Page.IsValid Then

Dim cont As Int32 = 0

Dim di As DataGridItem

For Each di In dgplandesarrollo.Items

Dim responsabilidadjefe As TextBox = New TextBox

responsabilidadjefe = CType(di.FindControl("jefe"), TextBox)

Dim responsabilidaddh As TextBox = New TextBox

responsabilidaddh = CType(di.FindControl("dh"), TextBox)

Dim responsabilidadcolaborador As TextBox = New TextBox

responsabilidadcolaborador = CType(di.FindControl("colaborador"), TextBox)

Dim tempresa As TextBox = New TextBox

tempresa = CType(di.FindControl("tempresa"), TextBox)

Dim tcolaborador As TextBox = New TextBox

tcolaborador = CType(di.FindControl("tcolaborador"), TextBox)

Dim id As Int32 = dgplandesarrollo.DataKeys.Item(cont)

Try

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

panelmensajes.Visible = True

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

Catch ex As Exception

panelmensajes.Visible = True

lblmensajes.Text = ex.Message

End Try

cont += 1

Next

End If

End Sub


This is my HTML datagrid

<asp:DataGrid id=dgplandesarrollo runat="server" Visible="False"
Width="100%" AutoGenerateColumns="False">
<ItemStyle CssClass="itemdg">
</ItemStyle>

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

<Columns>
<asp:TemplateColumn HeaderText="Competencia y Comportamiento">
<ItemTemplate>
<P>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.cadena") %>' Font-Bold="True" Font-Size="Small" ForeColor="Red">
</asp:Label></P>
<TABLE class=letras id=Table3 borderColor=#000000 cellSpacing=0
borderColorDark=#ffffff cellPadding=1 width="100%" border=1>
<TR>
<TD class=titulodg colSpan=2><STRONG><FONT size=1>PLAN DE DESARROLLO PARA
ESTE COMPORTAMIENTO</FONT></STRONG></TD></TR>
<TR>
<TD class=letras>Responsabilidad Jefe Inmediato
<asp:RequiredFieldValidator id=RequiredFieldValidator1 runat="server"
ErrorMessage="*"
ControlToValidate="jefe"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=jefe runat="server" Width="200px" CssClass="textboxes"
Height="38px" TextMode="MultiLine"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabilidad Desarrollo Humano
<asp:RequiredFieldValidator id=RequiredFieldValidator2 runat="server"
ErrorMessage="*" ControlToValidate="dh"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=dh runat="server" Width="200px" CssClass="textboxes"
Height="30px" TextMode="MultiLine"></asp:TextBox></TD></TR>
<TR>
<TD>Responsabilidad Colaborador
<asp:RequiredFieldValidator id=RequiredFieldValidator3 runat="server"
ErrorMessage="*"
ControlToValidate="colaborador"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=colaborador runat="server" Width="200px"
CssClass="textboxes" Height="38px"
TextMode="MultiLine"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Empresa
<asp:RequiredFieldValidator id=RequiredFieldValidator4 runat="server"
ErrorMessage="*"
ControlToValidate="tempresa"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=tempresa runat="server" Width="78px"
CssClass="textboxes"></asp:TextBox></TD></TR>
<TR>
<TD>Tiempo Colaborador
<asp:RequiredFieldValidator id=RequiredFieldValidator5 runat="server"
ErrorMessage="*"
ControlToValidate="tcolaborador"></asp:RequiredFieldValidator></TD>
<TD>
<asp:TextBox id=tcolaborador runat="server" Width="78px"
CssClass="textboxes"></asp:TextBox></TD></TR></TABLE>
<HR width="100%" color=red noShade SIZE=3>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False" DataField="idCompetencia"
HeaderText="idCompetencia"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="idcomportamiento"
HeaderText="idcomportamiento"></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
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:...
0
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...
2
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...
0
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...
5
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...
9
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 =...
9
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",...
0
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...
2
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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,...
0
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...

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.