会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
DODONG
博客园
首页
新随笔
联系
订阅
管理
公告
在DataGrid中实现Radio单选
//
-------------aspx--------------
<
asp:datagrid id
=
"
DataGrid1
"
runat
=
"
server
"
Font
-
Size
=
"
X-Small
"
AutoGenerateColumns
=
"
False
"
BorderColor
=
"
#CC9966
"
BorderStyle
=
"
None
"
CellPadding
=
"
4
"
AllowPaging
=
"
True
"
AllowSorting
=
"
True
"
PageSize
=
"
15
"
BorderWidth
=
"
1px
"
BackColor
=
"
White
"
Width
=
"
745px
"
DataKeyField
=
"
Coid
"
>
<
FooterStyle ForeColor
=
"
#330099
"
BackColor
=
"
#FFFFCC
"
></
FooterStyle
>
<
SelectedItemStyle Font
-
Bold
=
"
True
"
ForeColor
=
"
#663399
"
BackColor
=
"
#FFCC66
"
></
SelectedItemStyle
>
<
ItemStyle ForeColor
=
"
#330099
"
BackColor
=
"
White
"
></
ItemStyle
>
<
HeaderStyle Font
-
Bold
=
"
True
"
ForeColor
=
"
#FFFFCC
"
BackColor
=
"
#990000
"
></
HeaderStyle
>
<
Columns
>
<
asp:TemplateColumn HeaderText
=
"
Select
"
>
<
ItemTemplate
>
<
asp:Label id
=
"
Label2
"
Runat
=
"
server
"
></
asp:Label
>
<
asp:Label id
=
Label_Coid runat
=
"
server
"
Text
=
'
<%# DataBinder.Eval(Container, "DataItem.Coid") %>
'
></
asp:Label
>
</
ItemTemplate
>
</
asp:TemplateColumn
>
</
Columns
>
<
PagerStyle NextPageText
=
"
[Next]
"
PrevPageText
=
"
[Previous]
"
HorizontalAlign
=
"
Right
"
BackColor
=
"
Gainsboro
"
></
PagerStyle
>
</
asp:datagrid
>
<
asp:Label ID
=
"
Label3
"
Runat
=
"
server
"
></
asp:Label
>
//
------------.cs---------
//
绑定DataGrid中的ID值
private
void
DataGrid1_ItemDataBound(
object
sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if
(e.Item.ItemType
==
ListItemType.AlternatingItem
||
e.Item.ItemType
==
ListItemType.Item)
{
Label lbl;
lbl
=
(Label)e.Item.FindControl(
"
Label2
"
);
lbl.Text
=
"
<input type=radio name='myradiogroup' value=
"
+
((Label)e.Item.FindControl(
"
Label_Coid
"
)).Text
+
"
>
"
;
}
}
//
--确定提交----
private
void
SaveCompany_Click(
object
sender, System.EventArgs e)
{
Label3.Text
=
Request.Form[
"
myradiogroup
"
];
foreach
(DataGridItem i
in
DataGrid1.Items)
{
if
(i.ItemType
==
ListItemType.AlternatingItem
||
i.ItemType
==
ListItemType.Item)
{
Label r;
r
=
(Label)i.FindControl(
"
Label2
"
);
if
(r.Text.IndexOf(Label3.Text)
>
0
)
{
r.Text
=
"
<input type=radio name='myradiogroup' value=
"
+
((Label)i.FindControl(
"
Label_Coid
"
)).Text
+
"
Checked>
"
;
}
else
{
r.Text
=
"
<input type=radio name='myradiogroup' value=
"
+
((Label)i.FindControl(
"
Label_Coid
"
)).Text
+
"
>
"
;
}
}
}
posted on
2005-06-28 16:06
DODONG
阅读(
975
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2024 DODONG
Powered by .NET 8.0 on Kubernetes