[RESOLVED] I want to add counting number to radiobuttonlist items.How should i do that

Hi,

I want to add counting number to radiobuttonlist items, the radiobuttonlist is databounded.

    protected void rptQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
       
        RadioButtonList rbl = e.Item.FindControl("rblAnswer") as RadioButtonList;
        rbl.DataTextField ="AnswerText";
        rbl.DataValueField = "AnswerID";
        rbl.DataSource = BindAnswer(questionid);
        rbl.DataBind();
    }

tanx

sepid

One way is adding the Number in code behind using RadioButtonList DataBound event and another way is using Row_Number() function in your SELECT query.

protected void rblAnswer_DataBound(object sender, EventArgs e)
{
    RadioButtonList rblAnswer = (RadioButtonList)sender;
    foreach (ListItem item in rblAnswer.Items)
    {
        item.Text = string.Format("{0}.{1}", rblAnswer.Items.IndexOf(item) + 1, item.Text);
    }
}

Add OnDataBound="rblAnswer_DataBound" for the RadioButtonList in the repeater ItemTemplate. That's it.

thoughts on "[RESOLVED] I want to add counting number to radiobuttonlist items.How should i do that "

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>