일반적인 라디오버튼 추가로는 버튼 그룹이 지어지지 않기 때문에 (랜더링 순서에 의함) 리터럴을 통해서 추가시켜야함.
1. aspx 단의 GridView 에 ItemTemplate 항목으로 리터럴 추가
<asp:TemplateField HeaderText="선택">
<ItemTemplate>
<asp:Literal ID="RadioButtonMarkup" runat="server"></asp:Literal>
</ItemTemplate>
<ItemStyle Width="80" />
</asp:TemplateField>
2. cs 단에 리피터에 라디오버튼 추가 코드생성 ,SuppliersSelectedIndex 으로 선택한 라디오버튼의 인덱스(즉 RowIndex)를 가져올수 있음.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 라디오버튼 설정
Literal output = (Literal)e.Row.FindControl("RadioButtonMarkup");
output.Text = string.Format(
@"<input type='Radio' name='SuppliersGroup' " +
@"id='RowSelector{0}' value='{0}'", e.Row.RowIndex);
if (SuppliersSelectedIndex == e.Row.RowIndex)
output.Text += @" checked='checked'";
output.Text += " />";
}
}
private int SuppliersSelectedIndex
{
get
{
if (string.IsNullOrEmpty(Request.Form["SuppliersGroup"]))
return -1;
else
return Convert.ToInt32(Request.Form["SuppliersGroup"]);
}
}
'개발관련 > asp.net' 카테고리의 다른 글
[ASP.NET] GridView BoundField > TemplateField 테그(TAG) 표현 (0) | 2012.12.24 |
---|---|
게시판 페이징 구현 (0) | 2012.12.24 |
[ASP.NET 2.0] GRIDVIEW 내용을 EXCEL 로 저장 (추가 : 숫자컬럼 지정 및 공동모듈로 뺄때 유의점 ) (0) | 2012.12.24 |
[ASP.NET] 브라우저의 언어정보 가져오기 (0) | 2012.12.24 |
[ASP.NET 2.0] GRIDVIEW 내용을 EXCEL 로 저장 (HTML 방식 : 공통모듈화 + @ ) (0) | 2012.12.24 |