我有一个asp数据网格,其中一个列有一个输入
<asp:DataGrid ID="dgItem" runat="server" Width="100%" CssClass="TableList" AutoGenerateColumns="False" PagerStyle-Visible="False">
<Columns>
<asp:TemplateColumn HeaderText="Disc %">
<HeaderStyle HorizontalAlign="Right" CssClass="ListHeader"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" Width="6%" CssClass="TdList"></ItemStyle>
<ItemTemplate>
<input class="Input" onkeypress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode != 46 && event.keyCode != 45) event.returnValue=false;"
id="txtDiscRate" style="width: 100%; text-align: right" value="0.00" name="txtDiscRate"
runat="server" onchange="checkrate();">
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Visible="False"></PagerStyle>
</asp:DataGrid>
如何通过VB.net代码设置该列的值 此列是第10个单元格。在第一个单元格中,有一个值应设置为第10列
所以,我尝试了以下......但没有工作。
Dim lnDiscRate As Double
Double.TryParse(lodgGrid.Cells(1).Text, lnDiscRate)
Dim loDiscRate As HtmlInputText
For Each lodgGrid In dgItem.Items
loDiscRate = lodgGrid.Cells(10).FindControl("txtDiscRate")
loDiscRate.Value = lnDiscRate 'Not working :(
loDiscRate.Enabled = True 'this is Working..
Next
请帮助!!
得到别的东西。当我这样做时
CType(lodgGrid.FindControl("txtDiscRate"), HtmlInputText).Value = 10 ' Working
CType(lodgGrid.FindControl("txtDiscRate"), HtmlInputText).Value = lnDiscRate ' Not Working
答案 0 :(得分:0)
在DataGrid上实现ItemDataBound并使用以下
Private Sub dgItem_ItemDataBound(sender As Object, e As DataGridItemEventArgs) Handles dgItem.ItemDataBound
'Get the text value of the second cell as stated above, if you want the first use 0
Dim lnDiscRate As String
lnDiscRate = e.Item.Cells(1).Text
'set the text value of the desired input to the string found above...
CType(e.Item.FindControl("txtDiscRate"), HtmlInputText).Value = lnDiscRate
End Sub