想要使用ASP.NET从数据库中检索单选按钮列表值 [英] Wants to retrieve radio button list value from database using ASP.NET

查看:116
本文介绍了想要使用ASP.NET从数据库中检索单选按钮列表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void LoadData()
    {
        SqlDataAdapter da = new SqlDataAdapter("Select Quantity from Client_StandardPostcardRequest where Edition_Id=" + Session["Edition_ID"].ToString() + " and Exhibitor_ID=" + Session["Exhibitor_ID"].ToString() + "", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            int i = (int)ds.Tables[0].Rows[0]["Quantity"];
            rblQuantity.SelectedItem.Text = i.ToString();
        }
    }





我的尝试:



我已经尝试了上面的代码

我已经在按钮提交时将单选按钮列表的值插入数据库但是当我想从数据库中检索值到asp时页面值也是提取但是特定的单选按钮没有被检查。

请帮我解决这个问题



What I have tried:

I have tried the above code
I have inserted value of radio button list into database on button submit but when i want to retrieve value from database to the asp page value is also fetching but the particular radio button does not get checked.
Please help me in solving this issue

推荐答案

试试

try
string value = ds.Tables[0].Rows[0]["Quantity"].ToString();
           ListItem targetItem = rblQuantity.Items.FindByValue(value);
           if (targetItem != null)
               targetItem.Selected = true;



使用 ListItemCollection.FindByValue方法 [ ^ ]根据

使用 ListItemCollection.FindByText方法 [ ^ ]根据 text


use ListItemCollection.FindByValue Method [^] to find the radiobutton based on value
use ListItemCollection.FindByText Method [^] to find the radio button based on text


这篇关于想要使用ASP.NET从数据库中检索单选按钮列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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