RadioButtonList Question

4 views
Skip to first unread message

Arun

unread,
Oct 4, 2005, 11:05:04 AM10/4/05
to .NetIndia
Hi Frndz,

How to pass dataList(one field) value to a Radiobutton List ??

Regards,
Arun.M.D

sankar

unread,
Oct 4, 2005, 12:37:39 PM10/4/05
to Techdot...@googlegroups.com
Hi Arun
i think u asking abt binding a field from database to the radiobuttonlist.If so the follwing code will be usefull
 
 SqlConnection SqlCon = new SqlConnection("ConnectionString");
  SqlCommand SqlCmd = new SqlCommand("SELECT FieldName1(like Text), FieldName2(like id) FROM TableName", SqlCon);
  SqlCon.Open();
  rbl.DataSource = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
  rbl.DataTextField = "FieldName1";
  rbl.DataValueField = "FieldName2";
  rbl.DataBind();

 

Regards

Sankar


Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort.

Arun

unread,
Oct 5, 2005, 6:57:40 AM10/5/05
to .NetIndia
hi,
I tried above example. But itz not get output .


Can any other method is possible to bind a datalist value to
RadioButton List Web contro??

Regards,
Arun.M.D

SkyMania

unread,
Oct 5, 2005, 8:31:14 AM10/5/05
to .NetIndia
Its working fine with the follwoing code

string strqry;
strqry = "SELECT PRODUCTID,PRODUCTNAME FROM PRODUCTS WHERE PRODUCTNAME
LIKE 'A%'";
Scmd = new SqlCommand(strqry,Con);
Con.Open();
SDR = Scmd.ExecuteReader();
rbl.DataSource = SDR;
rbl.DataTextField = "PRODUCTNAME";
rbl.DataValueField = "PRODUCTID";
rbl.DataBind();


Regards,
SkyMania

Arun

unread,
Oct 5, 2005, 8:41:46 AM10/5/05
to .NetIndia
Hi,

When i use above coding it says "rbl" is not declared error....

Arun

unread,
Oct 5, 2005, 8:45:20 AM10/5/05
to .NetIndia
Hi,

I used like this....

myconn1 = New
SqlConnection("server=localhost;DataBase=Banking;Trusted_Connection=True")
mycommand = New SqlCommand("Select * from
Adm_Super_LoginMaster", myconn1)
myconn1.Open()
myread = mycommand.ExecuteReader()
myread.Read()
rbl.DataSource = myread
rbl.DatavalueField = "Adm_id"
rbl.DataBind()
myread.Close()
myconn1.Close()

In this coding it shows erron on this line
"rbl.DataSource = myread
"

And ERROR is:
Object variable or With block variable not set.

Regards,
Arun.M.D

SkyMania

unread,
Oct 6, 2005, 12:55:33 AM10/6/05
to .NetIndia
Hai,
Please check your connection..and try to bind it with datagrid.
And remove myRead.Read() also, otherwise it will bind only the
first record.

Regards,
SkyMania

Arun

unread,
Oct 5, 2005, 8:44:34 AM10/5/05
to .NetIndia
Reply all
Reply to author
Forward
0 new messages