|
|
|
ต้องการให้ checkboxใน gridview เลือกได้ครั้งเดียวค่ะ ต้องทำอย่างไร asp.net c# |
|
|
|
|
|
|
|
หน้า Design .aspx
Code (C#)
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GvData" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="KEY" />
<asp:TemplateField HeaderText="CB1" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox runat="server" ID="CB1" OnCheckedChanged="CB1_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CB2" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox runat="server" ID="CB2" Enabled="true" OnCheckedChanged="CB2_CheckedChanged"
AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CB3" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox runat="server" ID="CB3" Enabled="true" OnCheckedChanged="CB3_CheckedChanged"
AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
หน้า Code Behind .aspx.cs
Code (C#)
protected void CB1_CheckedChanged(object sender, EventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
CheckBox cb1 = (CheckBox)GvData.Rows[index].FindControl("CB1");
CheckBox cb2 = (CheckBox)GvData.Rows[index].FindControl("CB2");
CheckBox cb3 = (CheckBox)GvData.Rows[index].FindControl("CB3");
if (cb1.Checked)
{
cb2.Checked = false;
cb3.Checked = false;
}
else
{
}
}
protected void CB2_CheckedChanged(object sender, EventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
CheckBox cb1 = (CheckBox)GvData.Rows[index].FindControl("CB1");
CheckBox cb2 = (CheckBox)GvData.Rows[index].FindControl("CB2");
CheckBox cb3 = (CheckBox)GvData.Rows[index].FindControl("CB3");
if (cb2.Checked)
{
cb1.Checked = false;
cb3.Checked = false;
}
else
{
}
}
protected void CB3_CheckedChanged(object sender, EventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
CheckBox cb1 = (CheckBox)GvData.Rows[index].FindControl("CB1");
CheckBox cb2 = (CheckBox)GvData.Rows[index].FindControl("CB2");
CheckBox cb3 = (CheckBox)GvData.Rows[index].FindControl("CB3");
if (cb3.Checked)
{
cb1.Checked = false;
cb2.Checked = false;
}
else
{
}
}
hope it helps, happy coding :)
|
|
|
|
|
Date :
2013-05-13 13:13:23 |
By :
C2oWisComing |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เยี่ยม
|
|
|
|
|
Date :
2013-05-14 06:31:57 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณค่ะ
|
|
|
|
|
Date :
2013-05-14 09:48:10 |
By :
mushroomsn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|