问:

模板列一:
<asp:datagrid ></FooterStyle>
 </asp:TemplateColumn>
 </Columns>
</asp:datagrid>

模板列二:

            <asp:TemplateColumn HeaderText="身份证号">
                <ItemTemplate>
                    <asp:Label ID="Label" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.trad")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateColumn>

取值:
我用
 ((string)((TextBox)MyDataGrid.Items[j].Cells[i].Controle[j])).Text.ToString()
取单元格中的数据,系统编译不通过错误是:
 error CS0104: “TextBox”是不明确的引用
请高手指点
______________________________________________________________________________________________
答1:
我又改为
((string)((Label)MyDataGrid.Items[j].Cells[i].Controle[j])).Text.ToString()
取单元格中的数据,系统编译不通过错误是:
 error CS0104: “Label”是不明确的引用
如果强行运行,我取出的值为空

______________________________________________________________________________________________
答2:
你要根据情况获取DataGrid中的控件的值,看你的写法说明你是要获取DataGrid中所有列中包含TextBox文本框中的数值, 不如判断一下是否已经找到这个控件再判断取值,我这有VB.net的写法,请见量:
  For j = 0 To MyDataGrid.Items.Count - 1
      For i = 0 To MyDataGrid.Items.Cells.Count - 1
          If  Not Ctype(MyDataGrid.Items(j).Cells(i).Controls,TextBox) _
              Is Nothing Then
              strValue = Ctype(MyDataGrid.Items(j).Cells(i).Controls,TextBox).Text
          End If
      Next i
  Next j
______________________________________________________________________________________________
答3:
看看下面的方法如何?? 没有测试过,估计应该可以的。

<asp:datagrid ></FooterStyle>
 </asp:TemplateColumn>
 </Columns>
</asp:datagrid>

访问:
MyDataGrid.Items[j].Cells[i].Text;

相关文章: