Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Gridview checkbox buttons , +
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" "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"
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
        CellPadding="4" ForeColor="Black" GridLines="Horizontal" Height="241px"
        Width="374px">
            <Columns>
                <asp:TemplateField HeaderText="Select">
                    <ItemTemplate>
                <asp:CheckBox ID="gcb" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                                <asp:TemplateField HeaderText="ID">
                    <ItemTemplate>
                        <%#Eval("id")  %>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <%#Eval("name")  %>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="designation">
                    <ItemTemplate>
                        <asp:DropDownList ID="dd_desghnation" runat="server">
                            <asp:ListItem> --Select--</asp:ListItem>
                         
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Details">
                    <ItemTemplate>
                <asp:Button ID="gb" runat="server" Text="Show"/>
                    </ItemTemplate>
                </asp:TemplateField>
                
            </Columns>
            <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" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>
</blockquote>
 

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)
        {
            gv();
 
        }
 
    }
    public void gv()
    {
 
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ltest"].ToString());
        con.Open();
        string str = "select * from ltest";
        SqlCommand cmd = new SqlCommand(str,con);
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
 
        if (dt.Rows.Count > 0)
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
            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";
                bind_dropdownlist.DataBind();
            }
 
        }
 

    }
    }
 
Posted 16-Mar-12 14:28pm
nachia243

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

  Print Answers RSS
0 OriginalGriff 371
1 Sergey Alexandrovich Kryukov 269
2 CB Sharma 79
3 RyanDev 75
4 PhilLenoir 70
0 Sergey Alexandrovich Kryukov 6,676
1 OriginalGriff 6,056
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 16 Mar 2012
Copyright © CodeProject, 1999-2014
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