Solved

Gridview Databinding help

Posted on 2007-04-05
4
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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