使用sqldatareader从表值绑定下拉列表 [英] to bind the dropdown list from table value using sqldatareader

查看:54
本文介绍了使用sqldatareader从表值绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int brand = int.Parse(dr[8].ToString());
               string b_id = (brand - 1).ToString();
               ddbrandname.Items.FindByValue(b_id).Selected = true;







这是我的代码,我从表中通过sqldatareader得到'id',在我的下拉列表中select为0.

Text |价值

选择 - 0

chennai - 1

trichy - 2

马杜赖 - 3



如果,3作为我的读者价值并且通过上面的代码进行im绑定,它会显示错误,

但是如果我从3减少1个值(3- 1)= 2。



如果它是2,它的工作pakka,如果它的3显示错误,




this is my code,i am getting 'id' from table through sqldatareader ,in my drop down list the "select" as 0.
Text |value
select - 0
chennai - 1
trichy - 2
Madurai - 3

if , 3 as my reader value and i m binding by the above code,it shows error,
but if i decrease 1 value from 3 like (3-1) =2 .

if it is 2 ,its working pakka,if its 3 its shows error,

推荐答案

在品牌变量中,如果您获得的价值为1,2和2。 3然后你可以直接在下拉列表中设置所选的值为



In the brand variable if you are getting value as 1, 2 & 3 then you can directly set the selected value in dropdown as

ddbrandname.SelectedValue=brand.ToString();





这应该可以肯定!!!!



This should work for sure!!!!


这篇关于使用sqldatareader从表值绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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