Click here to Skip to main content
12,949,826 members (69,851 online)
Rate this:
Please Sign up or sign in to vote.
Hi All,

I have a big clarification in grid view, this question something interesting and also little duff.

I have table of three field namely id, name and destination

I know already how to add and display this three columns in grid view including check box & button for each row generated and fetching third column in drop down list.

I need to know when i checked the check box of particular column,then the drop down list item is selected and last finally the button is click, the output needed is another grid view (nested grid view)displaying the select row information.

I know its very interesting and simple for experts?

aspx code

<<blockquote class="FQ"><div class="FQA">Quote:</div>%@ Page Language="C#" AutoEventWireup="true" CodeFile="ltest.aspx.cs" Inherits="ltest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
        CellPadding="4" ForeColor="Black" GridLines="Horizontal" Height="241px"
                <asp:TemplateField HeaderText="Select">
                <asp:CheckBox ID="gcb" runat="server" />
                                <asp:TemplateField HeaderText="ID">
                        <%#Eval("id")  %>
                <asp:TemplateField HeaderText="Name">
                        <%#Eval("name")  %>
                <asp:TemplateField HeaderText="designation">
                        <asp:DropDownList ID="dd_desghnation" runat="server">
                            <asp:ListItem> --Select--</asp:ListItem>
                <asp:TemplateField HeaderText="Details">
                <asp:Button ID="gb" runat="server" Text="Show"/>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />

cs code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;
public partial class ltest : System.Web.UI.Page
    DropDownList bind_dropdownlist;
    protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
    public void gv()
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ltest"].ToString());
        string str = "select * from ltest";
        SqlCommand cmd = new SqlCommand(str,con);
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        if (dt.Rows.Count > 0)
            GridView1.DataSource = dt;
            foreach (GridViewRow grdRow in GridView1.Rows)
                bind_dropdownlist = (DropDownList)(GridView1.Rows[grdRow.RowIndex].Cells[2].FindControl("dd_desghnation"));
                bind_dropdownlist.DataSource = dt;
                bind_dropdownlist.DataValueField = "ID";
                bind_dropdownlist.DataTextField = "detination";

Posted 16-Mar-12 14:28pm

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,749
CHill60 3,380
Maciej Los 2,953
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 16 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100