This message was discovered on ASPFriends.com 'aspngvb' list.
| Administrator |
-- Moved from [aspngdatagridrepeaterdatalist] to [aspngvb] by Let the good times roll <Click here to reveal e-mail address> --
Hello All,
I am trying to grab the value of a HTMLInputHidden in a datagrid. This is the code I am using:
Dim dgi As DataGridItem CType(dgi.Cells(0).Controls(2), HTMLInputHidden).ToString
The position is right, but I keep getting an error. Does anyone know how to grab the value of an HTMLInputHidden from a datagrid?
Thanks.
John
|
|
| |
| |
| Darren Neimke |
Try something like:
Dim val As String val =3D CType(e.Item.Cells(0).Controls(2), HtmlInputHidden).ToString()
-----Original Message----- From: Administrator [mailto:Click here to reveal e-mail address]=20 Sent: Friday, July 26, 2002 10:39 AM To: aspngvb Subject: [aspngvb] CType
-- Moved from [aspngdatagridrepeaterdatalist] to [aspngvb] by Let the good times roll <Click here to reveal e-mail address> --
Hello All,
I am trying to grab the value of a HTMLInputHidden in a datagrid. This is the code I am using:
Dim dgi As DataGridItem CType(dgi.Cells(0).Controls(2), HTMLInputHidden).ToString
The position is right, but I keep getting an error. Does anyone know how to grab the value of an HTMLInputHidden from a datagrid?
Thanks.
John | [aspngvb] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT
|
|
| |
|
| |
| Darren Neimke |
Actually, let me explain further (because my example is still wrong!!)
You had:
Dim dgi As DataGridItem CType(dgi.Cells(0).Controls(2), HTMLInputHidden).ToString
So you are grabbing the Control at Controls(2) - of dgi (is dgi an *instance* of a DataGrid at this point in time?) - , Casting it to HTMLInputHidden, then calling ToString() against that *object*.
Basically, you want to use the Cast to grab an *instance* of the actual HTMLInputHidden object, then use it's properties in the usual manner.
Let's presume that we are attempting to access that control from within the OnItem event handler of a DataGrid...
Protected Sub ItemCommand(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
End Sub
From within that handler, you can use *casting* to access a specific DataGridItem...
=09 Dim dgi As DataGridItem dgi =3D CType(e.Item, DataGridItem)
Then you can access the members of that DataGridItem by making calls against your instance:
Dim ctl As Control
For Each ctl In dgi.Cells(0).Controls ... Next
Of course, in your case, if you know exactly where to look you can go directly to it using the appropriate Cast:
Dim htmlInput As HtmlInputHidden htmlInput =3D CType(e.Item.Cells(0).Controls(2), HtmlInputHidden)
Then, rather than calling ToString() against the *object*, you call it against the *property* that you are accessing:
Dim str As String =3D htmlInput.Value
|
|
| |
|
| |
| Administrator |
Hello Darren,
I try what you have below but I get the following error:
Compiler Error Message: BC30408: Method 'Public Sub sub_Buy(sender As = Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)' does not = have the same signature as delegate 'Delegate Sub EventHandler(sender As = Object, e As System.EventArgs)'.
Line 45: </table> Line 46: </ItemTemplate> Line 47: <FooterTemplate><Asp:Button ID=3D"btnPurchase" = Text=3D"Purchase Addesses" OnClick=3D"sub_Buy" Runat=3D"server" /> Line 48: </FooterTemplate> Line 49: </ASP:TemplateColumn>
Here is the exact datagrid:
<form id=3D"Form1" method=3D"post" runat=3D"server"> <asp:DataGrid ShowFooter=3D"True" CellPadding=3D"2" CellSpacing=3D"2" = ID=3D"dgCart" DataKeyField=3D"ShoppingCartID" ShowHeader=3D"True" = AlternatingItemStyle-BackColor=3D"LemonChiffon" = AutoGenerateColumns=3D"False" Runat=3D"server" = HeaderStyle-BackColor=3D"LemonChiffon"> <Columns> <Asp:TemplateColumn HeaderStyle-BorderWidth=3D"0" = ItemStyle-BorderWidth=3D"0" FooterStyle-BorderWidth=3D"0"> <ItemTemplate> <Asp:CheckBox ID=3D"chkTest" Checked=3D"True" Runat=3D"server" /> <input type=3D"hidden" id=3D"WID" value=3D"<%# = Container.DataItem("WomanID")%>"> </ItemTemplate> <FooterTemplate><asp:Button ID=3D"btnDelete" Text=3D"Remove" = Runat=3D"server" onclick=3D"sub_DeleteCartItem" /> </FooterTemplate> </Asp:TemplateColumn> <Asp:TemplateColumn HeaderStyle-BorderWidth=3D"0" = ItemStyle-BorderWidth=3D"0" FooterStyle-BorderWidth=3D"0"> <HeaderTemplate> Picture </HeaderTemplate> <ItemTemplate> <a href=3D"profile.aspx?UID=3D<%# Container.DataItem("WomanID")%>" = target=3D"main"><img src=3D"thumb.aspx?id=3D<%# = Container.DataItem("MainImage")%>" Height=3D"50" border=3D"0"></a> </ItemTemplate> </ASP:TemplateColumn> <Asp:TemplateColumn HeaderStyle-BorderWidth=3D"0" = ItemStyle-BorderWidth=3D"0" FooterStyle-BorderWidth=3D"0"> <HeaderTemplate> Contact </HeaderTemplate> <ItemTemplate> <table align=3Dleft class=3Dnoborder> <tr> <td><%# Container.DataItem("CustomerFirstName")%></td><td><%# = Container.DataItem("City")%>, <%# Container.DataItem("Country")%></td> </tr> </table> </ItemTemplate> <FooterTemplate><Asp:Button ID=3D"btnPurchase" Text=3D"Purchase = Addesses" OnClick=3D"sub_Buy" Runat=3D"server" /> </FooterTemplate> </ASP:TemplateColumn> </Columns> </Asp:DataGrid> </form>
And the exact function:
Sub sub_Buy(ByVal sender As Object, ByVal e As = DataGridItemEventArgs) Dim i As Integer =3D 0 Dim cb As CheckBox Dim dgi As DataGridItem Dim chk As String Dim chkString As String Dim htmlInput As HtmlInputHidden Dim str As String For Each dgi In dgCart.Items chkTest =3D e.Item.Cells(0).Controls(0) If chkTest.Checked Then htmlInput =3D e.Item.Cells(0).Controls(1) str =3D htmlInput.Value chk +=3D (i + 1) & "=3D" & str & "&" End If i +=3D 1 Next chkString =3D "?num=3D" & i & "&" & chk Server.Transfer("buy.aspx" & chkString) End Sub
I have tried all of the other methods suggested, and I can't figure out = the problem. =20
Thanks,
John
-----Original Message----- From: Darren Neimke [mailto:Click here to reveal e-mail address] Sent: Thursday, July 25, 2002 9:35 PM To: aspngvb Subject: [aspngvb] RE: CType
Actually, let me explain further (because my example is still wrong!!)
You had:
Dim dgi As DataGridItem CType(dgi.Cells(0).Controls(2), HTMLInputHidden).ToString
So you are grabbing the Control at Controls(2) - of dgi (is dgi an *instance* of a DataGrid at this point in time?) - , Casting it to HTMLInputHidden, then calling ToString() against that *object*.
Basically, you want to use the Cast to grab an *instance* of the actual HTMLInputHidden object, then use it's properties in the usual manner.
Let's presume that we are attempting to access that control from within the OnItem event handler of a DataGrid...
Protected Sub ItemCommand(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
End Sub
From within that handler, you can use *casting* to access a specific DataGridItem...
=09 Dim dgi As DataGridItem dgi =3D CType(e.Item, DataGridItem)
Then you can access the members of that DataGridItem by making calls against your instance:
Dim ctl As Control
For Each ctl In dgi.Cells(0).Controls ... Next
Of course, in your case, if you know exactly where to look you can go directly to it using the appropriate Cast:
Dim htmlInput As HtmlInputHidden htmlInput =3D CType(e.Item.Cells(0).Controls(2), HtmlInputHidden)
Then, rather than calling ToString() against the *object*, you call it against the *property* that you are accessing:
Dim str As String =3D htmlInput.Value
| [aspngvb] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT
|
|
| |
|
| |
| Administrator |
Hello All,
I found the problem. The problem is that you can not (or at least I = can not find a way) get data from a non .net control that is in a = datagrid. Even looping through the controls does not make a = HTMLInputHidden show up. What I ended up doing was attaching the data I = wanted to another control and using the SPLIT command to get the piece = that I wanted. (ex Control Value=3D"Data1-Data2". Then = varControl.Split("-").)
Anyway, thanks for trying to help.
John
-----Original Message----- From: Administrator=20 Sent: Friday, July 26, 2002 6:48 AM To: aspngvb Subject: [aspngvb] RE: CType
Hello Darren,
I try what you have below but I get the following error:
Compiler Error Message: BC30408: Method 'Public Sub sub_Buy(sender As = Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)' does not = have the same signature as delegate 'Delegate Sub EventHandler(sender As = Object, e As System.EventArgs)'.
Line 45: </table> Line 46: </ItemTemplate> Line 47: <FooterTemplate><Asp:Button ID=3D"btnPurchase" = Text=3D"Purchase Addesses" OnClick=3D"sub_Buy" Runat=3D"server" /> Line 48: </FooterTemplate> Line 49: </ASP:TemplateColumn>
Here is the exact datagrid:
<form id=3D"Form1" method=3D"post" runat=3D"server"> <asp:DataGrid ShowFooter=3D"True" CellPadding=3D"2" CellSpacing=3D"2" = ID=3D"dgCart" DataKeyField=3D"ShoppingCartID" ShowHeader=3D"True" = AlternatingItemStyle-BackColor=3D"LemonChiffon" = AutoGenerateColumns=3D"False" Runat=3D"server" = HeaderStyle-BackColor=3D"LemonChiffon"> <Columns> <Asp:TemplateColumn HeaderStyle-BorderWidth=3D"0" = ItemStyle-BorderWidth=3D"0" FooterStyle-BorderWidth=3D"0"> <ItemTemplate> <Asp:CheckBox ID=3D"chkTest" Checked=3D"True" Runat=3D"server" /> <input type=3D"hidden" id=3D"WID" value=3D"<%# = Container.DataItem("WomanID")%>"> </ItemTemplate> <FooterTemplate><asp:Button ID=3D"btnDelete" Text=3D"Remove" = Runat=3D"server" onclick=3D"sub_DeleteCartItem" /> </FooterTemplate> </Asp:TemplateColumn> <Asp:TemplateColumn HeaderStyle-BorderWidth=3D"0" = ItemStyle-BorderWidth=3D"0" FooterStyle-BorderWidth=3D"0"> <HeaderTemplate> Picture </HeaderTemplate> <ItemTemplate> <a href=3D"profile.aspx?UID=3D<%# Container.DataItem("WomanID")%>" = target=3D"main"><img src=3D"thumb.aspx?id=3D<%# = Container.DataItem("MainImage")%>" Height=3D"50" border=3D"0"></a> </ItemTemplate> </ASP:TemplateColumn> <Asp:TemplateColumn HeaderStyle-BorderWidth=3D"0" = ItemStyle-BorderWidth=3D"0" FooterStyle-BorderWidth=3D"0"> <HeaderTemplate> Contact </HeaderTemplate> <ItemTemplate> <table align=3Dleft class=3Dnoborder> <tr> <td><%# Container.DataItem("CustomerFirstName")%></td><td><%# = Container.DataItem("City")%>, <%# Container.DataItem("Country")%></td> </tr> </table> </ItemTemplate> <FooterTemplate><Asp:Button ID=3D"btnPurchase" Text=3D"Purchase = Addesses" OnClick=3D"sub_Buy" Runat=3D"server" /> </FooterTemplate> </ASP:TemplateColumn> </Columns> </Asp:DataGrid> </form>
And the exact function:
Sub sub_Buy(ByVal sender As Object, ByVal e As = DataGridItemEventArgs) Dim i As Integer =3D 0 Dim cb As CheckBox Dim dgi As DataGridItem Dim chk As String Dim chkString As String Dim htmlInput As HtmlInputHidden Dim str As String For Each dgi In dgCart.Items chkTest =3D e.Item.Cells(0).Controls(0) If chkTest.Checked Then htmlInput =3D e.Item.Cells(0).Controls(1) str =3D htmlInput.Value chk +=3D (i + 1) & "=3D" & str & "&" End If i +=3D 1 Next chkString =3D "?num=3D" & i & "&" & chk Server.Transfer("buy.aspx" & chkString) End Sub
I have tried all of the other methods suggested, and I can't figure out = the problem. =20
Thanks,
John
-----Original Message----- From: Darren Neimke [mailto:Click here to reveal e-mail address] Sent: Thursday, July 25, 2002 9:35 PM To: aspngvb Subject: [aspngvb] RE: CType
Actually, let me explain further (because my example is still wrong!!)
You had:
Dim dgi As DataGridItem CType(dgi.Cells(0).Controls(2), HTMLInputHidden).ToString
So you are grabbing the Control at Controls(2) - of dgi (is dgi an *instance* of a DataGrid at this point in time?) - , Casting it to HTMLInputHidden, then calling ToString() against that *object*.
Basically, you want to use the Cast to grab an *instance* of the actual HTMLInputHidden object, then use it's properties in the usual manner.
Let's presume that we are attempting to access that control from within the OnItem event handler of a DataGrid...
Protected Sub ItemCommand(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
End Sub
From within that handler, you can use *casting* to access a specific DataGridItem...
=09 Dim dgi As DataGridItem dgi =3D CType(e.Item, DataGridItem)
Then you can access the members of that DataGridItem by making calls against your instance:
Dim ctl As Control
For Each ctl In dgi.Cells(0).Controls ... Next
Of course, in your case, if you know exactly where to look you can go directly to it using the appropriate Cast:
Dim htmlInput As HtmlInputHidden htmlInput =3D CType(e.Item.Cells(0).Controls(2), HtmlInputHidden)
Then, rather than calling ToString() against the *object*, you call it against the *property* that you are accessing:
Dim str As String =3D htmlInput.Value
| [aspngvb] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT
| [aspngvb] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT
|
|
| |
|
|
|
|
|