Is it Possible to assign a dynamic ID to a RadiobuttonList??????

B

Brian

I have a datagrid that is listing a bunch of questions from my DB.. I
am creating a radiobuttonlist for each question to give me a yes or no
answer. I would like to use the "QuestionCode" column from that
database to assign the radiobuttonlist ID. Is this possible??????
 
E

Elton Wang

Hi Brian,

It is absolutely possible.

However, unless you have some special requirement, in most
case it's not necessary. Because even you assign a static
id to any control in the datagrid, you can easily get its
reference in many events such as datagrid_ItemCommand,
datagrid_UpdateCommand, datagrid_EditCommand, and so on,
by e.Item.FindControl("staticID").


Anyway, following code snippet shows how to dynamically
assign id to RadioButtonList in datagrid_ItemCreated event

foreach (Control ctrl in e.Item.Cells
[rblColIndex].Controls )
{
string ctrlName = ctrl.GetType().FullName;
if (ctrlName.Equals
("System.Web.UI.WebControls.RadioButtonList"))
{
ctrl.ID = assignID;
}
}

Elton Wang
(e-mail address removed)
 
B

Brian Ciarcia

Elton,

Thanks for the response. Here is my problem. Maybe you can help me come
up with a better solution. I am storing 8 groups of questions in a SQL
db. The QuestionHTML column holds the HTML code that will display the
group of questions and two radio buttons. Based on who logs in, it will
display the appropriate group of questions in a datagrid. my problem
now is that I need to iterate through each question and enter each
question as an individual record in the database. I just don't know how
to do it.. I can't get it to work using radiobuttonlists or just using
plain radio buttons... i'm new to asp.net so i am completely stumped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top