Click here to Skip to main content
15,887,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have written a code where more dropdown list should be displayed in grid view from the database where
they should be displayed in columns...
plz help me out...

code:
code for aspx:
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UpdateClientMapping.aspx.cs"
    Inherits="AttendanceWinmethods.UpdateClientMapping" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Client Mapping Details
    </div>
    <div>
        <br />
        <br />
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84"
            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
            Width="500px" OnRowDataBound="GridView2_RowDataBound" >
            <Columns>
              <asp:TemplateField HeaderText="ParentClientID">
                    <HeaderStyle HorizontalAlign="Left" Width="150px" />
                    <ItemStyle HorizontalAlign="Left" />
                    <ItemTemplate>
                        <%#Eval("ParentClientID")%>
                        <asp:DropDownList ID="ddlParentClientID" runat="server">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="IntermediateClientID">
                    <HeaderStyle HorizontalAlign="Left" Width="150px" />
                    <ItemStyle HorizontalAlign="Left" />
                    <ItemTemplate>
                        <%#Eval("IntermediateClientID")%></ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlIntermediateClientID" runat="server">
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ActualClientID">
                    <HeaderStyle HorizontalAlign="Left" Width="150px" />
                    <ItemStyle HorizontalAlign="Left" />
                    <ItemTemplate>
                        <%#Eval("ActualClientID")%></ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlActualClientID" runat="server">
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" />
                        <asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>




code for aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace AttendanceWinmethods
{
    public partial class UpdateClientMapping : System.Web.UI.Page
    {
        string strConnection = ConfigurationManager.ConnectionStrings["SQLConnection"].ToString();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)

                BindData();
        }


        #region Business Layer

        private void BindData()
        {
            //Bind the grid view

            GridView2.DataSource = GetClientMappingDetails();

            GridView2.DataBind();

        }


        protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                
                    DropDownList ddlParentClientID = (DropDownList)e.Row.FindControl("ddlParentClientID");

                    //Bind subcategories data to dropdownlist 

                    ddlParentClientID.DataTextField = "ClientName";

                    ddlParentClientID.DataValueField = "ClientID";
                    ddlParentClientID.DataSource = RetrieveParentClientID();
                    ddlParentClientID.DataBind();
                    DataRowView dr = e.Row.DataItem as DataRowView;

                    ddlParentClientID.SelectedValue = dr["ParentClientID"].ToString();




               

            }
        }

        

       
        #endregion;

        #region Data Layer

        private DataSet GetClientMappingDetails()
        {

            if (ViewState["ClientIDS"] != null)

                return (DataSet)ViewState["ClientIDS"];

            string strConnection = ConfigurationManager.ConnectionStrings["SQLConnection"].ToString();
            SqlConnection con = new SqlConnection(strConnection);

            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;
            cmd.CommandText = "WM_Prc_Get_ClientMappingDetails";
            cmd.CommandType = CommandType.StoredProcedure;

            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(ds);

            return ds;

        }
        #endregion;

        public object ds { get; set; }

        protected DataTable RetrieveParentClientID()
        {
            string strConnection = ConfigurationManager.ConnectionStrings["SQLConnection"].ToString();
            SqlConnection con = new SqlConnection(strConnection);
           // String str = "select CM.ParentClientID, CD.ClientName from ClientDetails as CD,ClientMapping as CM  where CD.ClientID=CM.ParentClientID";
            String str = "select ClientName, ClientID from ClientDetails";
            SqlCommand cmd = new SqlCommand(str, con);

            //cmd.Connection = con;
            //cmd.CommandText = "WM_Prc_Get_ClientMappingDetails";
            //cmd.CommandType = CommandType.StoredProcedure;
            DataTable dt = new DataTable();
            // DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(dt);
            return dt;
        }


        public object dt { get; set; }

        
        
        
        
     


    }   
}

EDIT:Code Formatting done and "" is removed.
Posted
Updated 28-Aug-12 20:58pm
v3
Comments
bhagirathimfs 29-Aug-12 2:43am    
Please ask the problem you are facing rather than post the whole code.
ridoy 29-Aug-12 2:55am    
what is your problem?
[no name] 29-Aug-12 2:57am    
where is the problem

1 solution

i want to integrate all those into another column how can i do it.
 
Share this answer
 
Comments
bhagirathimfs 29-Aug-12 3:08am    
Click "Have a Question and Comment"
And reply.

Don't post as solution(means:Don't write in Add your solutions here).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900