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

请教问题
GridView有个选择项放的是 客户端控件 单选Radio   绑定在GridView中 为什么选不中,点不了.   如何判断它被选中 必须得选中才能点下一步跳到下一个页面否则提示你没选择!! 请帮帮忙.最好是代码例子

------解决方案--------------------
ps:这个是vs2003的代码,你修改下就可以了

<%@ Page Language= "C# " %>
<%@ Import Namespace= "System.Data " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<script runat= "server ">

void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
LoadProductData();
}
}

protected void Button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(Request.Form[ "rbtnProduct "])) throw new Exception( "请选择一项 ");

string[] selectedRadioButtonValueArray = Request.Form[ "rbtnProduct "].Split( '$ '); // 获取被选中 radio 的值, rbtnProduct 为 radio 的客户端 name 属性值
int selectedItemIndex = int.Parse(selectedRadioButtonValueArray[0]); // 选择项索引
DataGridItem selectedGridItem = grdPro.Items[selectedItemIndex]; // 获取 DataGrid 的选择项
Response.Write(selectedGridItem.Cells[3].Text); // test
string whichRadioInItemFlag = selectedRadioButtonValueArray[1];
Response.Write(whichRadioInItemFlag);
if (whichRadioInItemFlag == "Flag1 ") {
// ...
}
else if (whichRadioInItemFlag == "Flag2 ") {
// ...
}
// more ...
//else {
//}
}

void LoadProductData()
{
grdPro.DataSource = CreateProductTable();
grdPro.DataBind();
}

#region sample data

static DataTable CreateProductTable()
{
DataTable tbl = new DataTable( "Products ");

tbl.Columns.Add( "ProductID ", typeof(int));
tbl.Columns.Add( "ProductName ", typeof(string));
tbl.Columns.Add( "CategoryID ", typeof(int));
DataRow row = tbl.NewRow();
row[0] = 1;
row[1] = "Chai ";
row[2] = 1;
tbl.Rows.Add(row);

row = tbl.NewRow();
row[0] = 2;
row[1] = "Chang ";
row[2] = 1;
tbl.Rows.Add(row);

row = tbl.NewRow();
row[0] = 3;
row[1] = "Aniseed Syrup ";
row[2] = 2;
tbl.Rows.Add(row);

row = tbl.NewRow();
row[0] = 4;
row[1] = "Chef Anton 's Cajun Seasoning ";
row[2] = 2;
tbl.Rows.Add(row);

row = tbl.NewRow();
row[0] = 5;
row[1] = "Chef Anton 's Gumbo Mix ";
row[2] = 2;
tbl.Rows.Add(row);

row = tbl.NewRow();
row[0] = 47;
row[1] = "Zaanse koeken ";
row[2] = 3;
tbl.Rows.Add(row);

row = tbl.NewRow();
row[0] = 48;
row[1] = "Chocolade ";
row[2] = 3;
tbl.Rows.Add(row);

row = tbl.NewRow();
row[0] = 49;
row[1] = "Maxilaku ";
row[2] = 3;
tbl.Rows.Add(row);

return tbl;
}

#endregion


</script>

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> DataGrid RadioButton </title>

</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:DataGrid ID= "grdPro " DataKeyField= "ProductID " runat= "server ">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
选项1: <input type= "r