|
send your code, so that i can check it
Padmanabhan
|
|
|
|
|
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void gridview1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
int count = 0;
for (int i = 0; i < gridview1.Rows.Count; i++)
{
GridViewRow rows = gridview1.Rows[i];
bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked;
if (ischeck)
{
count = count + 1;
Label1.Text = Convert.ToString(count);
}
}
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
StringBuilder str = new StringBuilder();
for (int i = 0; i < gridview1.Rows.Count; i++)
{
GridViewRow row = gridview1.Rows[i];
bool ischecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;
if (ischecked)
{
str.Append(gridview1.Rows[i].Cells[2].Text);
}
}
Response.Write(str.ToString());
}
}
Here is my code...
plz help where i missed to get the count.
thanks in advance
|
|
|
|
|
your aspx code plz
Padmanabhan
|
|
|
|
|
script type = "text/javascript">
function checkAll(objRef)
{
var GridView = objRef.parentNode.parentNode.parentNode;
var inputList = GridView.getElementsByTagName("input");
for (var i=0;i<inputList.length;i++)
{
//Get the Cell To find out ColumnIndex
var row = inputList[i].parentNode.parentNode;
if(inputList[i].type == "checkbox" && objRef != inputList[i])
{
if (objRef.checked)
{
//If the header checkbox is checked
//check all checkboxes
//and highlight all rows
//row.style.backgroundColor = "aqua";
inputList[i].checked=true;
}
else
{
//If the header checkbox is checked
//uncheck all checkboxes
//and change rowcolor back to original
//if(row.rowIndex % 2 == 0)
//{
//Alternating Row Color
// row.style.backgroundColor = "#C2D69B";
// }
// else
//{
//row.style.backgroundColor = "white";
//}
inputList[i].checked=false;
}
}
}
}
/script
/head
body
<asp:gridview id="gridview1" runat="server" autogeneratecolumns="False" allowpaging="True" pagesize="2" borderstyle="Solid" width="1500px" datasourceid="SqlDataSource1" onselectedindexchanged="gridview1_SelectedIndexChanged">
<pagersettings position="Top">
< PagerStyle CssClass="mypager" HorizontalAlign="Right"/>
<columns>
<asp:templatefield>
<headertemplate>
<asp:checkbox id="checkAll" runat="server" onclick="checkAll(this);" text="SelectAll">
<itemtemplate>
<asp:checkbox id="CheckBox1" runat="server" onclick="Check_Click(this)" autopostback="true" oncheckedchanged="CheckBox1_CheckedChanged1">
<asp:boundfield datafield="Empid" headertext="Empid" sortexpression="Empid">
<asp:boundfield datafield="FirstName" headertext="FirstName" sortexpression="FirstName">
<asp:boundfield datafield="MiddleName" headertext="MiddleName" sortexpression="MiddleName">
<asp:boundfield datafield="LastName" headertext="LastName" sortexpression="LastName">
<asp:boundfield datafield="Email" headertext="Email" sortexpression="Email">
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:dbdemoConnectionString3 %>"
="" selectcommand="SELECT [Empid], [FirstName], [MiddleName], [LastName], [Email] FROM [Dependents]">
No of Checkboxes selected <asp:label id="Label1" runat="server" text="Label" width="85px></asp:Label> <asp:Button ID=" btnsubmit"="" onclick="btnmail_Click">
here is my aspx code
|
|
|
|
|
<asp:checkbox id="CheckBox1" runat="server" <big="">onclick = "Check_Click(this)" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged1" />
//delete that onclick = "Check_Click(this)" event and check.
Padmanabhan
|
|
|
|
|
//aspx.cs page
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.IO;
using System.Globalization;
using System.Text;
public partial class Text : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(String));
DataRow dr = dt.NewRow();
dr["Name"] = "Padmanabhan";
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1["Name"] = "Varatharaman";
dt.Rows.Add(dr1);
DataRow dr2 = dt.NewRow();
dr2["Name"] = "Sathya";
dt.Rows.Add(dr2);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
int count = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow rows = GridView1.Rows[i];
bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked;
if (ischeck)
{
count = count+1;
Label1.Text = Convert.ToString(count);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder str = new StringBuilder();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool ischecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;
if (ischecked)
{
str.Append(GridView1.Rows[i].Cells[0].Text);
}
}
Response.Write(str.ToString());
}
}
//aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Text.aspx.cs" Inherits="Text" %>
<title>Untitled Page
<asp:label id="Label1" runat="server" text="Label">
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False">
<columns>
<asp:boundfield datafield="NAME" headertext="NAME">
<asp:templatefield headertext="CHECK">
<itemtemplate>
<asp:checkbox id="CheckBox1" runat="server" autopostback="True" oncheckedchanged="CheckBox1_CheckedChanged1">
<asp:button id="Button1" runat="server" onclick="Button1_Click" text="Button">
Padmanabhan
|
|
|
|
|
Thank you...
Thanx alot...For helping me
Now i am geting the count.
|
|
|
|
|
hello sir,
And one more question regarding this checkbox count.
when i have not selected any checkbox the label must show
"no records selected".
I tried this by using else block but failing to get
and i am having "select all" checkbox at the top and when i checked
that selectall checkbox it must similarly show the count..
Plz,help me....
i am very new to this asp.net world..
Thanks in advance
|
|
|
|
|
//java script
var TotalChkBx;
var Counter;
window.onload = function()
{
TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>');
Counter = 0;
}
function SelectAll(CheckBox)
{
var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
var TargetChildControl = "CheckBox1";
var Inputs = TargetBaseControl.getElementsByTagName("input");
for(var n = 0; n < Inputs.length; ++n)
if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)
Inputs[n].checked = CheckBox.checked;
Counter = CheckBox.checked ? TotalChkBx : 0;
if(Counter !=0)
document.getElementById('Label1').innerText = Counter;
else
document.getElementById('Label1').innerText = "no records selected";
}
//in your aspx
<headertemplate>
<asp:checkbox id="CheckBox2" runat="server" onclick="javascript:SelectAll(this);">
//your aspx.cs page
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
int count = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow rows = GridView1.Rows[i];
bool ischeck = ((CheckBox)rows.FindControl("CheckBox1")).Checked;
if (ischeck)
{
count = count+1;
}
if (count != 0)
{
Label1.Text = Convert.ToString(count);
}
else
{
Label1.Text = "no records selected";
}
}
}
Padmanabhan
modified on Thursday, May 28, 2009 4:20 AM
|
|
|
|
|
Thank you...
Thanx a million for helping me...
|
|
|
|
|
This is my Article. If you have any doubt in Grid related refer this site and vote if you like it.
GridView all in one[^]
Padmanabhan
|
|
|
|
|
hiiii,
I have a gridview with fileds Id,Name,Email,Citizenship and Flag
bounded to the gridview from the database.
And my gridview also having checkbox.
And one button submit.
when the checkbox is checked and the button is clicked i like to
update the flag column which is null to "selected".
plz tell me how i can do this...
Thanx in advance
|
|
|
|
|
for (int i = 0; i < Grid.Rows.Count; i++)
{
GridViewRow rows = Grid.Rows[i];
bool ischeck = ((Checkbox)rows.FindControl("Checkbox1")).Checked;
if (ischeck)
{
//your update query here
}
}
Padmanabhan
modified on Wednesday, May 27, 2009 9:24 AM
|
|
|
|
|
hi..
I am working on stocks manageent.I want updated price of shares.I am using rss feed.I have use grid view to make rss.But problem is i am not able to decode thhis xml rss.
Plz help how i cause rss to show updated stocks price.
here is code that i try-
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader("http://blogs.ibibo.com/sharetipsfree/feed/rss");
DataSet dataset = new DataSet();
dataset.ReadXml(reader);
GridView1.DataSource = dataset.Tables[2];
GridView1.DataBind();
}
|
|
|
|
|
The RSS that you have mentioned is about some definations.
However the above code is to read the XML and display same on the page.
But if you want your code to display the updated pricing, then the rss xml must be updated after some interval of time.
If you can do the same, only then report will display the updated values
|
|
|
|
|
|
Hi
The above link is not providing any rss.
If the same is rss then the link should be giving some xml file.
The link is accepting some query string arguments, reading and displaying the same on scree.
You cannot do any thing with this.
Search for RSS for the same
|
|
|
|
|
CommandArgument='<%# Bind("ID")>' is it possible to send id&name within the same command argument
|
|
|
|
|
//use like this
'<%# "Redirect.aspx?id=" + DataBinder.Eval(Container.DataItem,"ID")+ "&name=" + DataBinder.Eval(Container.DataItem,"name")%>'
Padmanabhan
|
|
|
|
|
I want to redirect to other web page. based on the click of ok button ,i used script of message box by using
ClientScript.RegisterStartupScript();
means after clicking ok button it must redirect to another page.
but if i put response.redirect() after the ClientScript.RegisterStartupScript() code. it automatically redirects to other page without displaying my message box, how to solve this problem.
pls give the code.
thanks in adv,
sanmbk
|
|
|
|
|
(i used script of message box by using
ClientScript.RegisterStartupScript()
send me the java script...
Padmanabhan
|
|
|
|
|
sanmbk wrote: i used script of message box by using
ClientScript.RegisterStartupScript();
means after clicking ok button it must redirect to another page.
Why dont you use the Client itself to do the redirection instead of coming back to the server and doing Response.Redirect.
In short you need to write a Javascript function which will execute on click of OK button.
function RedirectAfterMessage()
{
var message = "do you wanna redirect?";
if(confirm(message))
window.location = "www.google.com";
}
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I want to redirect to other web page. based on the click of ok button ,i used script of message box by using
ClientScript.RegisterStartupScript();
means after clicking ok button it must redirect to another page.
but if i put response.redirect() after the ClientScript.RegisterStartupScript() code. it automatically redirects to other page without displaying my message box, how to solve this problem.
pls give the code.
thanks in adv,
sanmbk
|
|
|
|
|
(i used script of message box by using
ClientScript.RegisterStartupScript();)
send me the java script...
Padmanabhan
|
|
|
|
|
Hi, I have used crystalreportviewer in one of my webpages.It works well in local pc.but after uploading it on the server, it started throwing some javascript error whenever we press print button or export button of crystalreportviewer.
the javascript error is : Object doesn't support this action.
Can anyone help me?
Thanks and regards
ARINDAM
|
|
|
|