Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bound checkbox in a DataGrid
Message
 
À
15/10/2008 08:48:04
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01354896
Message ID:
01355125
Vues:
24
>You are right and they look terrible being so dimmed you can hardly tell if they are checked or not. I think I may have figured out why I was getting a bad result appearing to not be bound at all. I do not like them however in this very dimmed state. I do not need to edit any rows in this situation however.

If you use a templated control you have a bit more control over it's appearance.

>>
>>>How about if I want to display an enumeratin value that corresponds to an integer in the data within a datagrid? So if I have a type column that can be a 0, 1, or 2 value but I want to display in the datagrid "Message", "Tip", "Location".
>>
>>if you simply want to display these values, you can (again) create a template column with no control inside.
>>In the RowDataBound event of the gridview, you can modify the "Text" property of the "cell" in that particular column.
>
>Thanks, I am going to give this a try today just so I know how to do this.

If it's display only, this is probably the simplest approach. Just cast the value back to the enum and convert it to a string. If you actually need to support editing, I generally just create a user control and add a drop down list to it. There isn't a direct way of binding to it, so you usually just create an array from the enum and use that instead, ex:
    public enum SampleList
    {
        FirstItem,
        SecondItem,
        ThirdItem,
        FourthItem
    }

Array names = Enum.GetNames(typeof(SampleList));
Array values = Enum.GetValues(typeof(SampleList));

for (int index = 0; index < names.Length; index++)
{
     this.cboEnum.Items.Add(new ListItem(names.GetValue(index).ToString(), values.GetValue(index).ToString()));
}
Then I'll just expose the drop down list's Text property, SelectedValue (among others) and set it in the calling form.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform