Datagrid中使用模版列RadioButtonList问题如何取值?

lg7020 2006-08-17 02:39:58
Datagrid中使用模版列RadioButtonList问题如何取值?
也就是如何在进行编辑一行时,取得模版列中RadioButtonList控件的选项,用e.Item.Cells[2].Text怎么不行呢?最后取得值为"System.Web.UI.LiteralControl“,如何取当前行的值呢?
...全文
273 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pol000 2006-08-17
  • 打赏
  • 举报
回复
mark
exiori 2006-08-17
  • 打赏
  • 举报
回复
FindControl
jimu8130 2006-08-17
  • 打赏
  • 举报
回复
你上个问题解决了?
jimu8130 2006-08-17
  • 打赏
  • 举报
回复
不能向你那样的取值,而应该先用findcontrol方法来定位控件!然后取值,你仔细看我上面的代码

from :http://dotnet.aspx.cc/ShowDetail.aspx?id=60B8B07E-A3DF-4AE5-B5F8-71204C7C8793
jimu8130 2006-08-17
  • 打赏
  • 举报
回复
void GetValues_Click(Object sender, EventArgs e) {
String Result = "";
foreach(DataGridItem dataGridItem in MyDataGrid.Items){
//Get name from cell[0]
String Name = dataGridItem.Cells[0].Text;
//Get text from textbox in cell[1]
String Age = ((TextBox)dataGridItem.FindControl("AgeField")).Text;
//Get Checked property of Checkbox control
bool IsGraduate = ((CheckBox)dataGridItem.FindControl("IsGraduateField")).Checked;

// get Values from Checkboxlist
String Skills = "";
foreach(ListItem item in ((CheckBoxList)dataGridItem.FindControl("CheckBoxList1")).Items){
if (item.Selected){
Skills += item.Value + ",";
}
}
Skills = Skills.TrimEnd(',');

//Get RadioButtonList Selected text
String Experience = ((RadioButtonList)dataGridItem.FindControl("RadioButtonList1")).SelectedItem.Text;

//Get DropDownList Selected text
String Degree = ((DropDownList)dataGridItem.FindControl("DropDownList1")).SelectedItem.Text;

// Build String to show result.
Result += Name;
Result += " [Age -" + Age + "] ";

if (IsGraduate){
Result += "Is Graduate , ";
}else{
Result += "Is not Graduate , ";
}

Result += "Has Skills[" + Skills + "] , ";

Result += "Has " + Experience + " Experience , And " ;

Result += "Has " + Degree + " Degree." ;

Result += "<br>";
}
ResultField.Text = Result;
}

c#?
jimu8130 2006-08-17
  • 打赏
  • 举报
回复
Public Sub GetValues_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GetValues.Click
Dim Result As String = ""
Dim dataGridItem As DataGridItem
For Each dataGridItem In MyDataGrid.Items
Dim Name As String = dataGridItem.Cells(0).Text

Dim AgeField As TextBox = dataGridItem.FindControl("AgeField")
Dim Age As Integer = System.Convert.ToInt64(AgeField.Text).ToString()

Dim IsGraduateField As CheckBox = dataGridItem.FindControl("IsGraduateField")
Dim IsGraduate As Boolean = IsGraduateField.Checked
Dim Skills As String = ""
Dim item As ListItem
Dim CheckBoxList1 As CheckBoxList = dataGridItem.FindControl("CheckBoxList1")
For Each item In CheckBoxList1.Items
If item.Selected Then
Skills = Skills + item.Value + ","
End If
Next
Skills = Skills.TrimEnd(",")

Dim RadioButtonList1 As RadioButtonList = dataGridItem.FindControl("RadioButtonList1")
Dim Experience As String = RadioButtonList1.SelectedItem.Text
Dim DropDownList1 As DropDownList = dataGridItem.FindControl("DropDownList1")
Dim Degree As String = DropDownList1.SelectedItem.Text
Result = Result + Name
Result = Result + "[年龄:" + Age.ToString() + "]"
Result += " "
If IsGraduate Then
Result += "已经毕业 , "
Else
Result += "没有毕业 , "
End If
Result += "技能:" + Skills + " , "
Result += "经验: " + Experience + " , 和 "
Result += "学位: " + Degree + "。"
Result += "<br>"
Next
ResultField.Text = Result
End Sub
vb的
Eddie005 2006-08-17
  • 打赏
  • 举报
回复
RadioButtonList rblst = (RadioButtonList)e.Item.Cells[2].Controls[1];
//或者RadioButtonList rblst = (RadioButtonList)e.Item.FindControls("RadioButtonList1");

然后就可以取得rblst的选中项了~

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧