![]() |
|
|
|||||||
![]() |
ASP Net - How can I get the value of a column in a datagrid? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 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 -- LUIS ESTEBAN VALENCIA MICROSOFT DCE 3. MIEMBRO ACTIVO DE ALIANZADEV http://spaces.msn.com/members/extremed/ Luis Esteban Valencia |
|
|
|
|
#2 |
|
Posts: 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" <> wrote in message news:%... > 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 > 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 > -- > > LUIS ESTEBAN VALENCIA > MICROSOFT DCE 3. > MIEMBRO ACTIVO DE ALIANZADEV > http://spaces.msn.com/members/extremed/ > > Ken Cox [Microsoft MVP] |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Loading 24,000 rows into C# .net Datagrid | Kagu | Software | 0 | 03-10-2009 06:51 PM |
| validating textbox inside datagrid | susan_1516 | Software | 0 | 11-09-2008 01:29 PM |
| Disable ASP Button in a Datagrid | ChrisClayko | General Help Related Topics | 0 | 08-02-2006 03:08 AM |
| DataGrid-Hyperlink column | thiyag2001 | Software | 2 | 08-01-2006 12:50 PM |
| Counting In Binary | Raymond | A+ Certification | 13 | 03-07-2004 07:28 PM |