日期:2014-05-18  浏览次数:20415 次

回传时读取datagrid中文本框中数值的问题
设计了一个datagrid,单元格都是textbox形式,需要用户输入数据(好多行),点击保存按钮,需要实现将这些数据都读取出来,
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   
  Dim arr_sl(100) As String
  Dim k As Integer
  For i As Integer = 0 To DataGrid1.Items.Count - 1

  For j As Integer = 1 To DataGrid1.Columns.Count - 1
  arr_sl(k) = DataGrid1.Items(i).Cells(j).Text
  k = k + 1
  Next
  Next

  bindData()

  End Sub
可是这样不行,因为DataGrid1.Items.Count 为0,我知道是因为回传的datagrid没有状态,可是那怎么获取这些输入的值呢?谢谢

------解决方案--------------------
VB 囧,我只会C#...不过思路都一样
前台:<asp:datagrid id="DataGrid1" runat="server" onupdatecommand="UpdateData" >
加上onupdatecommand="UpdateData" 
后台:
protected void UpdateData(object sender,DataGridCommandEventArgs e)
{
TextBox t;
DropDownList prgColumn;
t= (TextBox)DataGrid1.Items[e.Item.ItemIndex].FindControl("你的texboxid");
}