如何从radiobuttonlist的数据库中检索值? [英] how to retrive value from database for radiobuttonlist?

查看:92
本文介绍了如何从radiobuttonlist的数据库中检索值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从数据库中检索单选按钮列表..i的代码背后是什么..我有2个公和母的列表值..我想动态地检索数据. ...基于selectedtindexedchanged ..


提前thanxs

what is code behind for retriving value from database for radiobuttonlist..i have 2 list value male and female..i want to retrive data dynamically. ...based on selectedtindexedchanged..


thanxs in advance

推荐答案

您是否检查过文档?有一个很好的例子: ListControl.SelectedIndexChanged事件 [ ^ ]
Did you check the documentation? There''s quite good example: ListControl.SelectedIndexChanged Event[^]


sunil,

Design.aspx
Hi sunil,

Design.aspx
<div>
    
        <asp:radiobuttonlist id="RadioButtonList1" runat="server" xmlns:asp="#unknown">
            RepeatDirection="Horizontal">
        
    
    </div>



背后的代码:



Code Behind:

protected void Page_Load(object sender, EventArgs e)
   {
       string cs = ConfigurationManager.ConnectionStrings["samplecnstring"].ConnectionString;
       SqlConnection cn = new SqlConnection(cs);
       SqlCommand cmd = new SqlCommand("select countryname from country", cn);
       SqlDataAdapter da = new SqlDataAdapter(cmd);
       DataSet ds = new DataSet();
       da.Fill(ds, "country");

       RadioButtonList1.DataSource = ds;
       RadioButtonList1.DataTextField = "countryname";
       RadioButtonList1.DataValueField = "countryname";
       RadioButtonList1.DataBind();

   }


好好练习,
祝你玩得开心!!!


Practice well,
Have a good time!!!


这篇关于如何从radiobuttonlist的数据库中检索值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆