日期:2014-05-19  浏览次数:20453 次

在线调查系统的取值问题?or你有更好的思路?
数据库用两个表,一个存调查主题,另一个存对应主题的选项.
显示面页用DataList显示主题,并在ItemTemplate里放了个PlaceHolder用于显示该主题对应的选项,因为调查有单选或多选的可能,所不能直接放RodioButtonList或CheckBoxList.   datalist_ItemDataBound事件代码:
protected   void   dListShowSbject_ItemDataBound(object   sender,   DataListItemEventArgs   e)
        {
                if   (e.Item.ItemType   ==   ListItemType.Item   ||   e.Item.ItemType   ==   ListItemType.AlternatingItem)
                {
                        //给调查主题添加编号
                        if   (e.Item.ItemIndex   > =   0)
                        {
                                ((Label)e.Item.FindControl( "lblAutoID ")).Text   =Convert.ToString(e.Item.ItemIndex   +   1);
                        }
                        //邦定对应调查主题的选项
                        int   pollid   =   int.Parse(this.dListShowSbject.DataKeys[e.Item.ItemIndex].ToString());
                        string   selectMode   =   pl().GetPollSelectMode(pollid).ToString();//取得选择模式(selectmode)

                        RadioButtonList   rbl   =   new   RadioButtonList();
                        rbl.DataSource   =   pl().GetPollOptions(pollid);
                        rbl.DataValueField   =   "id ";
                        rbl.DataTextField   =   "options ";
                        CheckBoxList   cbl   =   new   CheckBoxList();
                        cbl.DataSource   =   pl().GetPollOptions(pollid);
                        cbl.DataValueField   =   "id ";
                        cbl.DataTextField   =   "options ";
                        PlaceHolder   pollHolder   =   (PlaceHolder)e.Item.FindControl( "pollHolder ");
                        if   (selectMode   ==   "1 ")//判断是否是单选
                        {
                                rbl.DataBind();