Solved

Gridview Databinding help

Posted on 2007-04-05
4
342 Views
Last Modified: 2008-01-09
I have a databind that returns all roles, the problem is would like to customize this control so that the actual role has all other columns included for example roleid, rolename, roledate etc.

the following only returns all roles and the header name is "item"
gvRoles.DataSource = System.Web.Security.Roles.GetAllRoles
gvRoles.DataBind()

    <asp:GridView ID="gvRoles" runat="server" AutoGenerateColumns="true" AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" AutoGenerateSelectButton="true">
                        </asp:GridView>

 SqlDataAdapter Adapter = new SqlDataAdapter(Command);
            DataSet RolesDS = new DataSet();
            try
            {
                SqlConn.Open();
                Adapter.Fill(RolesDS);
                int i = 0;
                roles = new string[RolesDS.Tables[0].Rows.Count];
                foreach (DataRow role in RolesDS.Tables[0].Rows)
                {
                    roles[i] = role["RoleNames"].ToString();
                    i++;
                }
            }
0
Comment
Question by:Padre_Corleone
  • 3
4 Comments
 
LVL 19

Expert Comment

by:DreamMaster
Comment Utility
I'm not exactly sure if I know what you mean. When you say "actual role" do you mean the selected role?

Cause in that case you will probably need to extend upon the gridview control, so that you have a different look for a selected row, or even a mouseover row for that matter.

Is that what you mean or am I totally off base here.

Regards,
Max.
0
 
LVL 7

Author Comment

by:Padre_Corleone
Comment Utility
RoleNames is the only Column return, how can i also get RoleID, CreatedDate
to display on my gridview?
0
 
LVL 19

Accepted Solution

by:
DreamMaster earned 500 total points
Comment Utility
You will have to also return them, just don't display them, so instead of using autogeneratecolumns="true" turn it to false and use binding of columns to show what you want.

If you do that, you can show Rolenames by default and you will need to write some logic to make sure that when selected you also show RoleID and CreatedDate..

Regards,
Max.
0
 
LVL 19

Expert Comment

by:DreamMaster
Comment Utility
Glad to have been helpful :)

Regards,
Max.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now