0

我有一个 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) &amp;&amp; event.keyCode != 46 &amp;&amp; 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
4

1 回答 1

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
于 2013-04-30T15:18:50.820 回答