Checking header checkbox checks all checkboxes in gridview

8 Comments


In gridview header write like this:

<HeaderTemplate>
<asp:CheckBox runat=”server” ID=”cboxhead” AutoPostBack=”true” OnCheckedChanged=”HeaderCheckedChanged”/>
</HeaderTemplate>

In cs file

protected void HeaderCheckedChanged(object sender, EventArgs e)//this is for header checkbox changed event
{

CheckBox cbSelectedHeader = (CheckBox)GridView1.HeaderRow.FindControl(“cboxhead”);//if u checked header checkbox automatically all the check boxes will be checked,viseversa
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cbSelected = (CheckBox)row.FindControl(“CheckBox1”);
if (cbSelectedHeader.Checked == true)
{
cbSelected.Checked = true;

}
else
{
cbSelected.Checked = false;
}

}

}

Advertisements

validate a control through Javascript from code behind

1 Comment


Hello If you want to validate a textbox where we can only enter numbers.

Fisrt write the javascript function in .aspx file.

eg:

<SCRIPT language=Javascript>
<!–
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;

return true;

}
//–>
</SCRIPT>

In the code behind in page_load event write the code for the text box control.

<!–

TextBox1.Attributes.Add(“Onkeypress”, “return isNumberKey(event)”);

>

Clearing all the textboxes after submitting the data

Leave a comment


Hello friends,

While we are doing some big entry screens after submitting we will erase all the content in textboxes.For that we will do erasing each and every textbox.

It will takes a lot of time . To Reduce the difficulty use the simple code below:

Control myForm = Page.FindControl(“Form1”);

foreach (Control ctl in myForm.Controls)

{

if (ctl.GetType().ToString().Equals(“System.Web.UI.WebControls.TextBox”))

(TextBox)ctl).Text = “”;

}

SQL Query to check whether a table exists or not in a database

2 Comments


SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME =
‘table Name’ AND TABLE_TYPE = ‘BASE TABLE’

%d bloggers like this: