Adding Tooltip for RadioButtonList Elements

My is RadioButtonList

tied to the database like this:

SqlDataAdapter adapter = new SqlDataAdapter("SELECT ItemsID,ItemsDescription FROM Items", con);
adapter.Fill(subjects);
rblUseCases.DataSource = subjects;
rblUseCases.DataTextField = "ItemsDescription";
rblUseCases.DataValueField = "ItemsID";          
rblUseCases.DataBind(); 

      

I need to add a new tooltip that will be displayed when the user hovers around any radio button. I am planning to add tooltip text as a new column Tooltip

in my database table Items

. How can I bind it to a switch?

+3


source to share


4 answers


The following code will display a tooltip on the radio button:

ListItem li=new ListItem("Manish","oopde");
li.Attributes.Add("title","zello");
RadioButtonList1.Items.Add(li);

      



For data binding, you can iterate over each element and add attributes to it. The databound and databinding event does not trigger for every item, which is why we had no other opportunity to implement the same.

+8


source


after databind write this code:

foreach( ListItem itm in rblUseCases.Items)
       {
          itm.Attributes.Add( "title", "value: " + itm.Text);
       }

      



Here itm.Text should be associated with the database.

+3


source


The answer can be found here

Code from article:

foreach(var item in rblUseCases.items)
{                   
       item.Attributes.Add("Title", rblUseCases.Item[i].Text)
}

      

If you want this value to come from your adapter, you will have to manually grab the corresponding values.

+1


source


try it

    rdoTest.DataSource = new string[]
    {
        "Hello",
        "World",
    }; 

    rdoTest.DataBind();

    foreach (ListItem item in rdoTest.Items)
    {
        item.Attributes["title"] = item.Text;
    }

      

thank

Dip

0


source







All Articles