By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,888 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,888 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.