Advertisement

09.02.2008 at 10:26AM PDT, ID: 23696727
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Bind DataGrid to hard coded values for demonstration purposes

Asked by dba123 in Programming for ASP.NET

I need to create a DataGrid that's bound by hard coded values that I spcify in code-behind for demonstration purposes.  We are gonna change it to actually bind to a data source later.

I'm not srue how to do this.  I'm used to binding to a data source.

Lets say I ahve the data Grid beow.  I started to create the header text from code-behind.  How would I actually hard code records and then bind the grid?

 

                                            <asp:datagrid id="dgTasks" runat="server"
                                                            allowsorting="true" pagesize="10" allowpaging="true" autogeneratecolumns="false" pagerstyle-visible="false"
                                                            width="100%" allowcustompaging="false" >
                                                            <selecteditemstyle cssclass="rowdetailactive"></selecteditemstyle>
                                                            <alternatingitemstyle borderstyle="none" cssclass="AlternatingRowStyle_middle"></alternatingitemstyle>
                                                            <itemstyle cssclass="rowdetail"></itemstyle>
                                                            <headerstyle cssclass="repeater_header"></headerstyle>
                                                            <columns>
                                                                  <asp:templatecolumn sortexpression="1">
                                                                        <headerstyle width="70px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                              <asp:image id="imgstatus" runat=server height="16px" width="16px" imageurl='<%#displayimage(databinder.eval(container, "dataitem.status").tostring())%>'>
                                                                              </asp:image>
                                                                              <%# displayclaimstatus(databinder.eval(container, "dataitem.RequestNumber").tostring())%>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                                  <asp:templatecolumn sortexpression="2">
                                                                        <headerstyle width="100px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                            <asp:hyperlink id="hplPriority" runat="server"><%# databinder.eval(container, "dataitem.Priority")%></asp:hyperlink>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                                  <asp:templatecolumn sortexpression="3">
                                                                        <headerstyle width="90px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                              <%# databinder.eval(container, "dataitem.Task")%>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                                  <asp:templatecolumn sortexpression="4">
                                                                        <headerstyle width="90px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                              <%# displaydate(databinder.eval(container, "dataitem.CreateDate"))%>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                                  <asp:templatecolumn sortexpression="5">
                                                                        <headerstyle width="90px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                              <%# displaydate(databinder.eval(container, "dataitem.ApplicationName"))%>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                                  <asp:templatecolumn sortexpression="6">
                                                                        <headerstyle width="140px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                              <%# databinder.eval(container, "dataitem.RequestedFor")%>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                                  <asp:templatecolumn sortexpression="7">
                                                                        <headerstyle width="180px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                              <%# databinder.eval(container, "dataitem.Status")%>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                                  <asp:templatecolumn>
                                                                        <headerstyle width="90px" wrap="false"></headerstyle>
                                                                        <itemtemplate>
                                                                              <%# displaydate(databinder.eval(container, "dataitem.Assigned"))%>
                                                                        </itemtemplate>
                                                                  </asp:templatecolumn>
                                                            </columns>
                                                            <pagerstyle visible="false"></pagerstyle>
                                                      </asp:datagrid>

Code-behind:

        private void LoadTasks()
        {
            //List<string> values = new List<string>();

            //values.Add("Sharepoint");
            //values.Add("Exchange Email Account");
            //values.Add("Office 2007 Enterprise");

            dgTasks.Columns[0].HeaderText = "Request #";
            dgTasks.Columns[0].HeaderText = "Priority";
            dgTasks.Columns[0].HeaderText = "Task";
            dgTasks.Columns[0].HeaderText = "Create Date";
            dgTasks.Columns[0].HeaderText = "Application Name";
            dgTasks.Columns[0].HeaderText = "Status";
            dgTasks.Columns[0].HeaderText = "Assigned";

            dgTasks.Items.Add(new ListItem(WebUtils.GetLabel("lblStatus"), "1"));


            dgTasks.DataSource = values;
            if (dgTasks != null)
                dgTasks.DataBind();
        }Start Free Trial
[+][-]09.02.2008 at 10:41AM PDT, ID: 22369574

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Programming for ASP.NET
Sign Up Now!
Solution Provided By: prairiedog
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628