• 控件及其数据传输


            首先是单选按钮,checkbox. 可以从工具箱中拖出,比如<asp:CheckBox ID="server"  Text="呵呵"/>   然后再建个button 按钮和label控件,方便取值,然后右键查看代码在后端写条件,在 button1.Click+=Button1_click;    它会在下面自动生成点击事件,然后在点击事件中取值,代码写:

    if(CheckBox1.Checked)

    Label1.Text = CheckBox1.Text    然后在页面中就可以将呵呵 取出来。因为单选按钮绑定数据库多的话就不会很好用,所以用CheckboxList这个控件,在这CheckboxList控件中有ListItem 这个属性,

    代码:<asp:ListItem Value="N001">汉族</asp:Listitem>

    单选一个的时候代码:if(checkBoxList1.SelectedItem!=null   )      //checkBoxList1.SelectedIndex !=-1

      Label1.Text=CheckBoxList1.SelectedItem.Value/Text;

    多选一个的时候代码:

       if(checkboxlist1.selecteditem!=null){

       string  s  =null;

            foreach(Listitem li  in   Listitem1.items){

             if(li.selected){

                  s  += li.value+ ","

     }

    }

    label1.text = s;

    }

    绑定数据库分为有默认值和没有默认值:

    有默认值的时候:

    foreach (Users u in ulist)
    {
    ListItem li = new ListItem(u.NickName, u.UserName);
    if (u.UserName == "xiaohua" || u.UserName == "wangwu")
    li.Selected = true;

    CheckBoxList1.Items.Add(li);
    }

    没有默认值得时候:

    CheckBoxList1.DataSource = ulist;
    CheckBoxList1.DataTextField = "NickName";
    CheckBoxList1.DataValueField = "Ucode";
    CheckBoxList1.DataBind();

     当所设置的内容要绑定数据库的时候代码如下:

    DropDownList4.DataSource = new UserNationData (). SelectAll();
    DropDownList4.DataTextField = "NationName";
    DropDownList4.DataValueField = "NationCode";
    DropDownList4.DataBind();

    在这里面要加上if(!IsPostBack)

    这样是为了防止刷新页面。

    跨页面传值:

    QueryString - 地址栏显示传值(get)

    Request - 获取请求对象
    Response - 响应对象

     <a href ="update.aspx?id=<%#Eval("Ids") %>" >修改</a>

    string ss = Request["id"]; 

    request 是string 类型的。

    **绑定日期的时候:

    RadioButtonList1.SelectedValue =u.Sex .ToString ();
    DropDownList1.Items .Add ( u.Birthday.Year.ToString ()) ;
    DropDownList2.Items.Add(u.Birthday.Month .ToString());

    绑定民族的时候:


    DropDownList4.DataSource = new UserNationData (). SelectAll();
    DropDownList4.DataTextField = "NationName";
    DropDownList4.DataValueField = "NationCode";
    DropDownList4.DataBind();
    DropDownList4.SelectedValue = u.Nation;

  • 相关阅读:
    angular二级联动菜单
    angular 实现自定义样式下拉菜单
    编程思想之回调
    编程思想之递归
    编程思想之迭代器
    阅读源码FluentScheduler
    改变spring-servlet.xml名字和默认位置
    thinkpad X1c 2018 插上电源风扇转速过快的解决办法
    python 和python-m 的区别
    电脑
  • 原文地址:https://www.cnblogs.com/yujiamin123/p/7295265.html
Copyright © 2020-2023  润新知