DataList, Repeater, GridView의 Checkbox 수치 문제
13565 단어 checkbox
1 <asp:DataList id="DataList1" runat="server" Width="100%" RepeatColumns="4" Font-Size="10pt">
2 <ItemTemplate>
3 <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="100%" bgColor="gainsboro" border="0">
4 <TR>
5 <TD align="center">
6 <asp:Label id=lblOName runat="server" Font-Size="10pt" Text='<%# DataBinder.eval_r(Container.DataItem,"nmenu_name")%>'>
7 </asp:Label>
8 <asp:Label id=lblID runat="server" Font-Size="10pt" Text='<%# DataBinder.eval_r(Container.DataItem,"nmenu_id")%>' Visible="False">
9 </asp:Label></TD>
10 </TR>
11 <TR>
12 <TD align="center">
13 <asp:CheckBoxList id="cbSelect" runat="server" Font-Size="10pt" RepeatColumns="2" Width="100%" BackColor="#FFE0C0"
14 RepeatDirection="Horizontal" DataTextField="nmenu_tname" DataValueField="nmenu_tid"></asp:CheckBoxList></TD>
15 </TR>
16 </TABLE>
17 </ItemTemplate>
18 </asp:DataList>
백그라운드 바인딩 CheckBox:
1 private void Page_Load(object sender, System.EventArgs e)
2 {
3 //
4 if(!IsPostBack)
5 {
6 if(Session["UID"]!=null&&Session["UID"].ToString()!="")
7 {
8 BindList();
9 BindCheckBox();
10 }
11 else
12 {
13 Server.Transfer("error.aspx");
14 }
15 }
16 }
17 private void BindList()
18 {
19 string sql = "select * from NewsOne";
20 DataList1.DataSource = ort.ExecuteToTable(sql);
21 DataList1.DataBind();
22 }
23 private void BindCheckBox()
24 {
25 foreach(DataListItem dli in DataList1.Items)
26 {
27 CheckBoxList cbl = (CheckBoxList)dli.FindControl("cbSelect");
28 Label lbl = (Label)dli.FindControl("lblID");
29 string sql = "select * from NewsTwo where nmenu_oid="+lbl.Text;
30 cbl.DataSource = ort.ExecuteToTable(sql);
31 cbl.DataBind();
32 }
33 }
CheckBox 수치:
1 string list = "";
2 foreach(DataListItem dli in DataList1.Items)
3 {
4 CheckBoxList cbSel = (CheckBoxList)dli.FindControl("cbSelect");
5 for(int i=0;i<cbSel.Items.Count;i++)
6 {
7 if(cbSel.Items[i].Selected == true)
8 {
9 list += cbSel.Items[i].Value + ",";
10 }
11 }
12 }
13 list = list.Trim(",".ToCharArray());
어떤 때는 값을 얻지 못하는 경우가 있는데, 나의 견해는if(! Is Post Back)가 부족하다는 것이다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
useRef() Hook을 사용하여 React Js에서 버튼이 있는 모든 확인란을 어떻게 선택/선택 취소합니까?useRef() Hook을 사용하여 React Js에서 버튼이 있는 모든 확인란을 어떻게 선택/선택 취소합니까? 이 게시물에서는 모든 확인란을 선택/선택 취소하는 방법에 대해 알아봅니다. useRef() 반응 후크 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.