How to use checkbox in datagrid using asp.net with csharp codeNRnarasiman rao14yAsked Sep 7, 2012, 8:29 PM EDT2 answersShareLinkedInXCopy linkSavehow to use checkbox in datagrid using asp.net with csharp codeplease send the design and coding Regards,Rao.2 AnswersKnow the answer? Post it. Somebody with the same question will find it here.Akkiraju IvaturiRank #474 · 5.2K points14y agoPosted Sep 7, 2012, 8:56 PM EDT0You can use the following article:http://www.c-sharpcorner.com/uploadfile/vipinakhil/checkun-check-checkboxes-items-in-Asp-Net-datagrid-using-javascript/0Akkiraju IvaturiRank #474 · 5.2K points14y agoPosted Sep 7, 2012, 8:58 PM EDT0Otherwise, use this code:<%@ Page Language="vb" Src="ChkBoxDataGrid.aspx.vb" Inherits="DotNetJohn.ChkBoxDataGrid" %> <!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN"> AutoGenerateColumns="False" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Vertical"> Text='<%# DataBinder.Eval(Container.DataItem,"CompanyName") %>' runat="server" /> Text='<%# DataBinder.Eval(Container.DataItem,"CustomerID") %>' Runat="server" /> Runat="server" Font-Name="Verdana" Font-Size="10px" /> Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Web.UI.WebControls Namespace DotNetJohn Public Class ChkBoxDataGrid : Inherits System.Web.UI.Page Protected btnShow As Button Protected dtgCusts As DataGrid Protected lblSelections As Label Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then btnShow.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to delete these rows?')") BindTheData End If End Sub Sub BindTheData Dim objConn As SqlConnection Dim objCmd As SqlCommand objConn = New SqlConnection(ConfigurationSettings.AppSettings("NorthwindConnection")) Dim strSql As String strSql = "SELECT Top 10 CustomerID, CompanyName, ContactName, " _ & "ContactTitle, City, Country, Phone FROM Customers" Try objCmd = New SqlCommand(strSql, objConn) objConn.Open dtgCusts.DataSource = objCmd.ExecuteReader() dtgCusts.DataBind() Catch Finally If objConn.State = ConnectionState.Open Then objConn.Close() objConn.Dispose() End If End Try End Sub Sub ShowSelections(sender As System.Object, e As System.EventArgs) Dim dgItem As DataGridItem Dim chkSelected As CheckBox Dim strCompanyName As String Dim strCustomerID As String lblSelections.Text = "Fooled Ya! The following rows were marked for deletion, " lblSelections.Text += "but not actually deleted:" For Each dgItem in dtgCusts.Items chkSelected = dgItem.FindControl("chkSelection") If chkSelected.Checked Then strCompanyName = CType(dgItem.FindControl("lblCompanyName"), Label).Text strCustomerID = CType(dgItem.FindControl("lblCustomerId"), Label).Text lblSelections.Text += "Company Name: " & strCompanyName & " | " lblSelections.Text += "Customer ID: " & strCustomerID & "" End If Next End Sub End Class End Namespace 0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign in
How to use checkbox in datagrid using asp.net with csharp codeNRnarasiman rao14yAsked Sep 7, 2012, 8:29 PM EDT2 answersShareLinkedInXCopy linkSavehow to use checkbox in datagrid using asp.net with csharp codeplease send the design and coding Regards,Rao.
Akkiraju IvaturiRank #474 · 5.2K points14y agoPosted Sep 7, 2012, 8:56 PM EDT0You can use the following article:http://www.c-sharpcorner.com/uploadfile/vipinakhil/checkun-check-checkboxes-items-in-Asp-Net-datagrid-using-javascript/0
Akkiraju IvaturiRank #474 · 5.2K points14y agoPosted Sep 7, 2012, 8:58 PM EDT0Otherwise, use this code:<%@ Page Language="vb" Src="ChkBoxDataGrid.aspx.vb" Inherits="DotNetJohn.ChkBoxDataGrid" %> <!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN"> AutoGenerateColumns="False" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Vertical"> Text='<%# DataBinder.Eval(Container.DataItem,"CompanyName") %>' runat="server" /> Text='<%# DataBinder.Eval(Container.DataItem,"CustomerID") %>' Runat="server" /> Runat="server" Font-Name="Verdana" Font-Size="10px" /> Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Web.UI.WebControls Namespace DotNetJohn Public Class ChkBoxDataGrid : Inherits System.Web.UI.Page Protected btnShow As Button Protected dtgCusts As DataGrid Protected lblSelections As Label Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then btnShow.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to delete these rows?')") BindTheData End If End Sub Sub BindTheData Dim objConn As SqlConnection Dim objCmd As SqlCommand objConn = New SqlConnection(ConfigurationSettings.AppSettings("NorthwindConnection")) Dim strSql As String strSql = "SELECT Top 10 CustomerID, CompanyName, ContactName, " _ & "ContactTitle, City, Country, Phone FROM Customers" Try objCmd = New SqlCommand(strSql, objConn) objConn.Open dtgCusts.DataSource = objCmd.ExecuteReader() dtgCusts.DataBind() Catch Finally If objConn.State = ConnectionState.Open Then objConn.Close() objConn.Dispose() End If End Try End Sub Sub ShowSelections(sender As System.Object, e As System.EventArgs) Dim dgItem As DataGridItem Dim chkSelected As CheckBox Dim strCompanyName As String Dim strCustomerID As String lblSelections.Text = "Fooled Ya! The following rows were marked for deletion, " lblSelections.Text += "but not actually deleted:" For Each dgItem in dtgCusts.Items chkSelected = dgItem.FindControl("chkSelection") If chkSelected.Checked Then strCompanyName = CType(dgItem.FindControl("lblCompanyName"), Label).Text strCustomerID = CType(dgItem.FindControl("lblCustomerId"), Label).Text lblSelections.Text += "Company Name: " & strCompanyName & " | " lblSelections.Text += "Customer ID: " & strCustomerID & "" End If Next End Sub End Class End Namespace 0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign in
Akkiraju IvaturiRank #474 · 5.2K pointsPosted Sep 7, 2012, 8:56 PM EDT
http://www.c-sharpcorner.com/uploadfile/vipinakhil/checkun-check-checkboxes-items-in-Asp-Net-datagrid-using-javascript/
Akkiraju IvaturiRank #474 · 5.2K pointsPosted Sep 7, 2012, 8:58 PM EDT
Fooled Ya! The following rows were marked for deletion, "
"
"