Solved

Gridview Databinding help

Posted on 2007-04-05
4
343 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
ID: 18862672
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
ID: 18862675
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
ID: 18862773
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
ID: 18862902
Glad to have been helpful :)

Regards,
Max.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

809 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