|
Why would you need to validate a label control? It's just there to display text (an do other events, but still). I don't think you can use the validator control to validate static controls like that(image control, label, ect.)
Can you explain a little more about why you need to validate your label?
|
|
|
|
|
why i need to validate label is
i have a calender control(ajax) and textbox(asp.net)
i was performed required field validation on textbox bec it is must and
should for me, and it allow me to edit the textbox date,
but i dont want to edit textbox..
i know the other way to keep this as readonly
finally
i dont want to show the layout of textbox so i need a label
and there must be data in label at runtime i.,e required field it is
|
|
|
|
|
So you have a textbox to edit the date value of your calender control, but you don't want to use the textbox to edit?
There's no way to use a label in they way your trying. Validation controls only work on input controls, which a label is not. Why dont you change the style of the textbox to seem like a label?
|
|
|
|
|
Hi
Thanks alot for your suggestion
The way ur are dealing is supurb.
|
|
|
|
|
hiii,
I am having a gridview with checkbox
and now i want the count of the no.of chechkboxes checked.
when the checkbox is checked then it must show the count as 1
with out any button event i have to get the count immediately after
checking the checkbox.
plz tell me how i can do this....
Thanks in advance
|
|
|
|
|
//write this is check box CheckBox1_CheckedChanged
//aspx
AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged1"
//aspx.cs
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;
}
}
}
Padmanabhan
|
|
|
|
|
Thank you...
your code works...
but the thing i need is after checking the checkbox immediately without
clicking any button i have to get the count.
plz help me in doing this
Thanks in advance
|
|
|
|
|
ya this code will give the count as soon as you check the checkbox....
i have written the code in "CheckBox1_CheckedChanged1"
Padmanabhan
|
|
|
|
|
hi....
Thank you for helping me..
yah i too got the count but i am getting the count after clicking
the button submit in my page.
I wrote the code in Checkbox1_ChechedChanged.
I took the count into the label.
plz tell me where i am missing...
Thanks in advance
|
|
|
|
|
ya you miss AutoPostBack="True"
if you give AutoPostBack="True" only it will fire the Checkbox1_ChechedChanged event.
Padmanabhan
|
|
|
|
|
hi,
I done all the things guided by you.
But i am unable to get the count after immedialtely checking the
chechbox.
Is there any alternate i tried alot but failed.
its very urgent for me.
plz help me.
Thanks in advance
|
|
|
|
|
Search it as "Bubble event".
|
|
|
|
|
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
|
|
|
|