 |
|
 |
If i have two cloumn each CheckBox , how can i your javascript apply to that, and also if one check box is checked other cloumn check box have to unchanged using javascript.
Tanveer
|
|
|
|
 |
|
 |
Using your example I have been trying without success to update a particular Gridview field/cell with a value, using the button click, for all rows with checkbox selected. Is this possible?
Ken Laing
|
|
|
|
 |
|
 |
You have no idea how long I have searched for a way to do this... And as it turns out, look how simple it is... Absolutely brilliant. Thanks so much for publishing this article. You get my '5' vote for this one!
|
|
|
|
 |
|
 |
Thanks a lot azamsharp, this article is really helpful
|
|
|
|
 |
|
 |
Here is my HTML code plz check it i still got checkbox value false though i select checkbox and do debug
Thanks in advance.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="address.aspx.vb" Inherits="WebApplication1.address" %>
<!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>Contact Address</title>
<%-- following script for close window--%>
<script lang ="ja" type ="text/javascript" >
function callclose()
{
var newwindow;
newwindow=window.close()
return true
}
</script>
<%-- following java scrpt is for check all checkboxes--%>
<script language=javascript>
function SelectAllCheckboxes(spanChk){
// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox= (spanChk.type=="checkbox") ?
spanChk : spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;
for(i=0;i
</head>
<body>
<form id="form1" runat="server">
<asp:LinkButton ID="lnkclose" runat="server" Style="left: 104px;
position: relative; top: 160px" OnClick ="lnkclose_click" >Close
<asp:GridView
ID="GridView1" runat="server" AutoGenerateColumns="False" Style="position: relative; top: 0px;">
<asp:TemplateField HeaderText ="Select">
<HeaderTemplate >
<input id="chkAll" önclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" />
</HeaderTemplate >
<asp:CheckBox ID="chk1" Enabled =true EnableTheming =true Visible =true EnableViewState =true runat="server" />
<asp:BoundField DataField ="name" HeaderText ="Name" />
<asp:BoundField DataField ="email" HeaderText ="Email-ID" />
<asp:Button ID="btnsubmmit" runat ="server" Text ="Submmit" />
<asp:CheckBox ID="chk1" runat="server" Style="left: -62px; position: relative;
top: 96px" />
</form>
</body>
</html>
============================================
and follow is my .aspx.vb code
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Partial Public Class address
Inherits System.Web.UI.Page
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim sread As SqlDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con = New SqlConnection("server=spick;database=address;uid=sa;pwd=sa")
con.Open()
Dim s As String
s = "select name,email from address"
cmd = New SqlCommand(s, con)
sread = cmd.ExecuteReader()
GridView1.DataSource = sread
GridView1.DataBind()
con.Close()
End Sub
Protected Sub lnkclose_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkclose.Click
lnkclose.Attributes.Add("onclick", "return callclose()")
End Sub
Protected Sub btnsubmmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmmit.Click
If IsPostBack = True Then
Dim str As StringBuilder = New StringBuilder()
' Select the checkboxes from the GridView control
Dim i As Integer
For i = 0 To GridView1.Rows.Count - 1 Step i + 1
Dim row As GridViewRow = GridView1.Rows(i)
Dim isChecked As Boolean = (CType(row.FindControl("chk1"), CheckBox)).Checked
If (isChecked) Then
str.Append(GridView1.Rows(i).Cells(2).Text)
End If
Next
' prints out the result
Response.Write(str.ToString())
End If
End Sub
End Class
Thnks,
Jigar Chaudhari,
Software Developer
|
|
|
|
 |
|
|
 |
|
 |
Check out the following article:
http://gridviewguy.com/ArticleDetails.aspx?articleID=228
Mohammad Azam
azamsharp@gmail.com
www.gridviewguy.com
videos.gridviewguy.com
Houston, TEXAS
|
|
|
|
 |
|
 |
Thank you for your Response.
I alrady solve my problem with one of other blogger help and your article use.
thanks a lots .
Jigar Chaudhari,
Software Developer.
hi
|
|
|
|
 |
|
 |
Hey jigar let me know how did you solve your problem..
Even I am facing the same hurdle..
Regards,
Namrata
|
|
|
|
 |
|
 |
Thank you vary much.
I alrady solve problem with one of another blogger vijay modi and your article helps.
I also visited your site ,really such a helpful idea given by you.
Thanks a lots,
hi
Jigar Chaudhari
Software Devloper,
Ahmedabad-India
|
|
|
|
 |
|
 |
hello sir,
I tried to use above article which was posted by mohmad but i have problem in
checkbox selection.
when i select checkbox then after when i debug this code in vb.net they give me false value rathere than true.
here is my code.
so plz give me a solution its a agrent.
Thanks to all u in advance.
Dim str As StringBuilder = New StringBuilder()
' Select the checkboxes from the GridView control
Dim i As Integer
For i = 0 To GridView1.Rows.Count - 1 Step i + 1
If CType(GridView1.Rows(i).FindControl("chk1"), CheckBox).Checked = True Then
str.Append(GridView1.Rows(i).Cells(2).Text)
End If
Next
' prints out the result
Response.Write(str.ToString())
hi
Worm Regards,
Jigar chaudhari
|
|
|
|
 |
|
 |
Please update your code with the following one:
===================================================
Dim str As StringBuilder = New StringBuilder()
' Select the checkboxes from the GridView control
Dim i As Integer
For i= 0 To GridView1.Rows.Count - 1
Dim gvRow As GridViewRow = GridView1.Rows(i)
If CType(gvRow.FindControl("chk1"), CheckBox).Checked Then
str.Append("testing")
End If
Next
===================================================
I think it will help you.
Regards...
VBM
Vijay Modi
Software Engineer.
|
|
|
|
 |
|
 |
the samething happen to my website appliaction, when i checked the check box,the value were still false. it seems that when i cheked the value in the gridview on client-side. it did not work. appreciate for considering it.
i am a boy from china. my engish is not pity good . so ask a excuse from everyone... thank you.
|
|
|
|
 |
|
 |
The ((CheckBox)row.FindControl("chkSelect")).Checked
always return false. Even i check all in the CheckBox Control. I can not get the result from it. Here is my code. Please help. I have try this a days. Thank you too much.
In default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="USER_ID" Width="366px" CellPadding="4" ForeColor="#333333" GridLines="None">
<asp:TemplateField HeaderText="Select">
<asp:CheckBox ID="chkSelect" runat="server" />
<HeaderTemplate>
</HeaderTemplate>
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<asp:TextBox ID="TextBox1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
</body>
</html>
In default.aspx.cs
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.OracleClient;
using System.Net;
public partial class _Default : System.Web.UI.Page
{
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
OracleConnection oracleConnection = new OracleConnection();
oracleConnection.ConnectionString = "user id = scott; data source=mysource; password=password";
oracleConnection.Open();
OracleCommand oraclecomm = new OracleCommand("select * from USER_INFO", oracleConnection);
OracleDataAdapter adapter = new OracleDataAdapter(oraclecomm);
ds = new DataSet();
adapter.Fill(ds, "table1");
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
if (isChecked)
{
TextBox1.Text += "1";
TextBox1.Text +=(GridView1.Rows[i].Cells[0].Text);
}
else
{
TextBox1.Text += "2";
TextBox1.Text += (GridView1.Rows[i].Cells[0].Text);
}
}
}
}
|
|
|
|
 |
|
 |
Hi,
thank you for the wonderful example. I tried this example on a simple test page and it works. But if I want to use this code in my page, which is using a MasterPage, it doesn't work anymore. It says "Object expected".
The GridView is placed in a ContentPlaceHolder. I tried to put the javascript code in the MasterPage and in the page which is using the MasterPage too, but both won't work. I tried to put a simple alert in the function and the alert isn't run at all... It seems asp.net can not find the function at all...
How should I do this right?
Thank you in advance.
|
|
|
|
 |
|
 |
Hi,
Can you paste some code so that I can look into it?
Thanks,
Azam
Mohammad Azam
.net Web Developer
Undergraduate Student ( Computer Science )
University of Houston Main Campus
email: azamsharp@gmail.com
www.azamsharp.net
www.gridviewguy.com
|
|
|
|
 |
|
 |
Hi Azam,
thank you for your fast response, but I found the solution.
I have put the javascript function in a .js file, and in the Page_Load() method from the page that is using the MasterPage, I register the script with this method:
ClientScript.RegisterClientScriptInclude("key", "./js/javascript.js");
Thank you.
|
|
|
|
 |
|
 |
I have a page which contains multiple gridviews, but when I check the checkbox in the header, it checks all the checkboxes in all the grids, rather than just the specified grid. Any solution?
McDude lives
|
|
|
|
 |
|
 |
function SelectAllCheckboxes(spanChk, chbxID)
{
var theBox= (spanChk.type=="checkbox") ? spanChk : spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
var checkbox = elm[i];
if(chbxID)
{
if(checkbox.id.search(chbxID) != -1)
{
if(elm[i].checked!=xState)
elm[i].click();
}
}
else
{
if(elm[i].checked!=xState)
elm[i].click();
}
}
}
Stephen
|
|
|
|
 |
|
 |
Hi oblivion
Thanx for the code...
I am really searching for this code but i am facing one more small problem
What should i pass inlieu of chbxID from the calling function?
What i mean to say..Let i take my example.
I have GridView with the following field
<asp:GridView ID="gv1" runat="server">
<asp:TemplateField HeaderText="Entity ID">
<HeaderTemplate>
<input id="chkAll" önclick="javascript:SelectAllCheckboxes(this, this.name);" runat="server" type="checkbox" />
</HeaderTemplate>
<asp:CheckBox ID="chkEntityID" runat="server" />
Currently i am passing "this.name". But thats is not working.Tha will check every checkbox in every GridView inside the form..I have tried everything document.getElementByID, ByName but nothing work for me..
Pls tell me what should i pass for chbxID
thanx for your valuable time in advance..
Bye
Deepak Gupta
|
|
|
|
 |
|
 |
I created a button to "Process" the checkbox selections, but upon handling the button click event, the GridView1 control has no rows. I tried scanning the rows on Page_Init, Page_LoadComplete, Page_PreRender, but strangely the GridView always has 0 rows.
When the page is rendered to the browser, the GridView is full of rows. Any suggestions?
Lance
|
|
|
|
 |
|
 |
I found that EnableViewState was set to false on my GridView, and this was the issue.
|
|
|
|
 |
|
 |
Hi,
I have gone through your site it is very good and havign good articles on that. But i have one query. I am working on problem that i have one Master-child pages. in that for one master record more then one child record are there.For that i am using gridview inside gridview.I am usign objectdatasource binding. Now i am successfully able to so gridview in gridview. now the problem comes when i use edit mode. In that case when click on edit command button it makes that row in edit mode and child grid shows with edit command button. Now what i want to do is first i will make changes in inside child grid using edit command button in it while keeping master grid row in edit mode. now problem is when press edit command of chils gird it just disappear. now can you help me in this ? how to work out ??
The main problem i have found in gridview is that when you place any control in any template column and write any event of that control gridview is not calling RowCommand first. It just directly call the perticular event. and afterwards call RowCommand.
Please help in this what should i have to do ?
|
|
|
|
 |
|
 |
Hi, Thanks for the good tips. I encountered a issue:
I have a page that contains 3 Gridview with Checkbox on the header for 'All' and checkbox on each rows. When I click one of the "All" checkbox, all three Gridview's checkbox are 'checked'. Can anyone guide me a javascript function to fix this issue. Thanks.
|
|
|
|
 |
|
 |
Is there a way to have the checkboxes stay checked across paging so that when you go to a new page on the girdview it remembers that previous items that were checked?
|
|
|
|
 |