C# 从数据网格获取数据
我正在用一些值填充一个C#DataGrid,我想在单击该值时从单元格中检索一个值。如何使用.NET1.1框架实现这一点 datagridview1在.net1.1中不可用C# 从数据网格获取数据,c#,.net,datagrid,C#,.net,Datagrid,我正在用一些值填充一个C#DataGrid,我想在单击该值时从单元格中检索一个值。如何使用.NET1.1框架实现这一点 datagridview1在.net1.1中不可用 只有windows应用程序才能执行以下操作: string strCell = (string)dataGridView1.CurrentCell.Value; 如果您谈论的是web/ASP.Net 1.1数据网格: 使用myDataGrid.Items获取一行 使用row.Cells[x]获取该行中的列 使用(TextBo
只有windows应用程序才能执行以下操作:
string strCell = (string)dataGridView1.CurrentCell.Value;
如果您谈论的是web/ASP.Net 1.1数据网格:
myDataGrid.Items
获取一行row.Cells[x]
获取该行中的列(TextBox)cell.FindControl(“TextBox1”)
获取单元格内的控件dataGridItem
是MyDataGrid.Items[x]的别名,其中x是(行)索引。这是因为下面的示例使用的是foreach循环,所以如果使用skimming,请记住这一点
遍历数据网格的行我们必须遍历DataGrid中的行,以获取该行中控件的值,所以 让我们先做吧。DataGrid控件有一个名为Items的属性, 它是对象DataGridItem的集合,表示 DataGrid控件中的单个项,我们可以使用此属性 按照以下六个步骤遍历DataGrid行
foreach(DataGridItem dataGridItem in MyDataGrid.Items){
}
从DataGrid中的绑定列获取值
我们的第一列是绑定列,需要写入一个值
在那个专栏里。DataGridItem具有名为Cells的属性,其
表示的单元格的TableCell对象的集合
争吵。TableCell的Text属性为我们提供了写入的值
那个特殊的细胞
//Get name from cell[0]
String Name = dataGridItem.Cells[0].Text;
获取DataGrid中TextBox控件的值现在,我们的第二列包含一个TextBox控件,我们需要获取一个Text属性
那个物体的形状。我们使用DataGridItem的FindControl方法
获取文本框的引用
//Get text from textbox in cell[1]
String Age =
((TextBox)dataGridItem.FindControl("AgeField")).Text;
从DataGrid中的复选框控件获取值
我们的第三纵队
在DataGrid中包含一个复选框Web控件,我们需要检查
该控件的Checked属性为true或false
//Get Checked property of Checkbox control
bool IsGraduate =
((CheckBox)dataGridItem.FindControl
("IsGraduateField")).Checked;
从DataGrid中的CheckBoxList Web控件获取值
这个案子
与上一个不同,因为复选框列表可能返回更多
然后选择一个值。我们必须反复检查复选框列表
要检查用户是否选择了特定项目的项目
// Get Values from CheckBoxList
String Skills = "";
foreach(ListItem item in
((CheckBoxList)dataGridItem.FindControl("CheckBoxList1")).Items)
{
if (item.Selected){
Skills += item.Value + ",";
}
}
Skills = Skills.TrimEnd(',');
从DataGrid中的RadioButtonList Web控件获取值
我们使用DataGridItem的FindControl方法获取
RadioButtonList,然后单击
RadioButtonList可从RadioButtonList获取所选项目
//Get RadioButtonList Selected text
String Experience =
((RadioButtonList)dataGridItem.FindControl("RadioButtonList1"))
.SelectedItem.Text;
从DataGrid中的DropDownList Web控件获取值
这类似于RadioButtonList。我使用此控件只是为了显示
它的工作方式与任何其他ListControl相同。同样地,你
可以像使用复选框列表一样使用ListBox Web控件
控制
//Get DropDownList Selected text
String Degree =
((DropDownList)dataGridItem.
FindControl("DropDownList1")).SelectedItem.Text;
您在单元格中单击的是什么…是链接按钮、文本还是按钮?