#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Smile Checkbox, DropDownlist and Button in Gridview


    Hi,


    I am new to Dot Net and I am basic knowledge of Grid view. I am trying to get some intermediate grid view knowledge. So please share and help me to get some knowledge.

    I am trying to know Check box,dropdownlist and button are generated for each row in Grid view.I am using C# language.
    If I checked the check box and button was clicked some action will happen, in between i true the property Autopostback of check box true, When check box is clicked the drop down list in the row should update the correct data for the row and if the button is clicked, the specific action is triggered, the selected row will display at the bottom of the page in nested grid view or separate grid view.

    Please share you thoughts. For your convenience I have attached my 50% of code with this query.. I hope I will get the answer soon.

    Aspx Code
    Code:
    <%@ 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>
    Cs code

    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();
                }
    
            }
    
    
        }
        }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0
    Hello
    all the requirements as you mentioned, I think dapfor .net grid can solve your problem- just check the .net grid features here
    www. dapfor.com/en/net-suite/net-grid/features

IMN logo majestic logo threadwatch logo seochat tools logo