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)가 부족하다는 것이다.

좋은 웹페이지 즐겨찾기