Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!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>
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
                
    <table>
        <tr>
            <td><asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false" 
                    Width="84px">
            
           <columns>
           <asp:TemplateField>
            <HeaderTemplate>
                Select
            </HeaderTemplate>
            <itemtemplate>
                <asp:CheckBox ID="chk1" runat="server" oncheckedchanged="chk1_CheckedChanged" AutoPostBack="true" />
                <asp:MutuallyExclusiveCheckBoxExtender ID="mchkext1" runat="server" Key="select" TargetControlID="chk1">
                
            </itemtemplate>
           
                <asp:TemplateField>
                <HeaderTemplate>Empid</HeaderTemplate>
                    <itemtemplate> <asp:Label ID="lblempid" Text='<%# Eval("EmpId")%>' runat="server"/></itemtemplate>

               
                <asp:TemplateField>
                <HeaderTemplate>Ename</HeaderTemplate>
                    <itemtemplate><asp:Label ID="lblename" Text='<%# Eval("Ename")%>' runat="server"/></itemtemplate>

               
                <asp:TemplateField>
                <HeaderTemplate>Address</HeaderTemplate>
                    <itemtemplate> <asp:Label ID="lbladdr" Text='<%# Eval("Address")%>' runat="server"/></itemtemplate>
              
              <asp:TemplateField>
                <HeaderTemplate>Phnno</HeaderTemplate>
                    <itemtemplate><asp:Label ID="lblphnno" Text='<%# Eval("phnno")%>' runat="server"/></itemtemplate>
               
               <asp:TemplateField>
                <HeaderTemplate>sal</HeaderTemplate>
                <itemtemplate><asp:Label ID="lblsal" Text='<%# Eval("sal")%>' runat="server"/></itemtemplate>
               
           </columns>
            </td>

        </tr>
        <tr>
            <td><asp:Button ID="btnsubmit" Text="Submit" runat="server" 
                    onclick="btnsubmit_Click" /></td>

                    <td><asp:Label ID="lbldisplay" runat="server"></td>
        </tr>
    </table>
    </div>
    </form>
</body>
</html>
C#
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;

public partial class Default2 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("server=RND3-10\\PRAYOG;user id=sa;password=prayoglabs@123;database=SDKC");

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        string s = "select * from employ";
        SqlDataAdapter da = new SqlDataAdapter(s, con);
        DataSet ds = new DataSet();
        da.Fill(ds, "employ");
        gridview1.DataSource = ds.Tables[0];
        gridview1.DataBind();
    }
    protected void chk1_CheckedChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow gv in gridview1.Rows)
        {
            CheckBox chk = (CheckBox)gv.FindControl("chk1");
            if (chk.Checked == true)
            {
                //lbldisplay.Text = gv.Cells[1].Text  + gv.Cells[2].Text + gv.Cells[3].Text+ gv.Cells[4].Text +  gv.Cells[5].Text;
                Label En = (Label)gv.FindControl("lblename");
                Label Eid = (Label)gv.FindControl("lblempid");
                Label Addr = (Label)gv.FindControl("lbladdr");
                Label phnno = (Label)gv.FindControl("lblphnno");
                Label sal = (Label)gv.FindControl("lblsal");
                lbldisplay.Text = Eid.Text +"\n"+ En.Text+"\n" + Addr.Text+"\n" + phnno.Text +"\n" +sal.Text;
                break;
            }
            
        }
        
    }
}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 15-Aug-11 21:44pm
v2
Comments
Abhinav S 16-Aug-11 3:10am    
So where is the problem?
senthil sennu 16-Aug-11 3:15am    
what is the Problem?? Where you are facing the problem?
Ashika s 16-Aug-11 3:19am    
what is the problem?

1 solution

You haven't open connection anywhere (con.Open()).
 
Share this answer
 
Comments
BoxyBrown 16-Aug-11 4:00am    
But if you write question and describe problem we can give you more exact answer.

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