Results 1 to 2 of 2

Thread: to bind multiple column values in bulletedlist...........

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2008
    Posts
    60

    Unhappy to bind multiple column values in bulletedlist...........

    hi 2 all,

    I have placed bulletedList in template field of gridview. Want to bind values from 4 column values in bulleted list. How do i do????????????


    Thanks and Regards,
    Vijay

  2. #2
    Junior Member
    Join Date
    Feb 2009
    Posts
    26

    Smile Re: to bind multiple column values in bulletedlist...........

    Hi,

    Yours is an interesting problem. I tried it out and managed to create a Gridview and do what you needed to do. I am giving below some code here. What my application does is to create a table with 4 columns called Col1, Col2, Col3 and Col4. This table has 2 records with values "1", "2" ,"3" and "4" for the 4 columns of the first row and "5", "6", "7" and "8" for the 4 columns of the second row of the table. These two rows are displayed as bulleted lists in the grid view. To try it out open a sample application in VS 2005 and substitute the code for the HTML page and the code behind for the Default page with what I give below.

    HTML code for Default.aspx

    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                             <asp:BulletedList ID="nbullet" runat="server">                                                  
                             </asp:BulletedList>                      
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            &nbsp;</div>
        </form>
    </body>
    </html>
    And here is the code for Default.aspx.cs

    Code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                DataTable dt = new DataTable("MyTable");
                dt.Columns.Add("Col1", System.Type.GetType("System.String"));
                dt.Columns.Add("Col2", System.Type.GetType("System.String"));
                dt.Columns.Add("Col3", System.Type.GetType("System.String"));
                dt.Columns.Add("Col4", System.Type.GetType("System.String"));
                DataRow dr = dt.NewRow();
                dt.Rows.Add(dr);
                dt.Rows[0]["Col1"] = "1";
                dt.Rows[0]["Col2"] = "2";
                dt.Rows[0]["Col3"] = "3";
                dt.Rows[0]["Col4"] = "4";
                DataRow dr1 = dt.NewRow();
                dt.Rows.Add(dr1);
                dt.Rows[1]["Col1"] = "5";
                dt.Rows[1]["Col2"] = "6";
                dt.Rows[1]["Col3"] = "7";
                dt.Rows[1]["Col4"] = "8";
    
                GridView1.DataSource = dt.DefaultView;
                GridView1.DataBind();
        }
    
    
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                BulletedList b =(BulletedList)e.Row.FindControl("nbullet");
                ListItem l1 = new ListItem(DataBinder.Eval(e.Row.DataItem, "Col1").ToString(), DataBinder.Eval(e.Row.DataItem, "Col1").ToString());
                ListItem l2 = new ListItem(DataBinder.Eval(e.Row.DataItem, "Col2").ToString(), DataBinder.Eval(e.Row.DataItem, "Col2").ToString());
                ListItem l3 = new ListItem(DataBinder.Eval(e.Row.DataItem, "Col3").ToString(), DataBinder.Eval(e.Row.DataItem, "Col3").ToString());
                ListItem l4 = new ListItem(DataBinder.Eval(e.Row.DataItem, "Col4").ToString(), DataBinder.Eval(e.Row.DataItem, "Col4").ToString());
                b.Items.Add(l1);
                b.Items.Add(l2);
                b.Items.Add(l3);
                b.Items.Add(l4);
            }
        }
    }
    If you run the code you will see 2 bulletted lists for the 2 records. I hope you can adapt this code to suit your purposes.

    Warm Regards,
    sr_jay
    Quote Originally Posted by vijaygpt
    hi 2 all,

    I have placed bulletedList in template field of gridview. Want to bind values from 4 column values in bulleted list. How do i do????????????


    Thanks and Regards,
    Vijay

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width