Prakash

Checkbox Gridview Javascript Multiple Delete Records

–JavaScript–

<script language=”javascript” type=”text/javascript”>

//user for select all checkbox
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<elm.length;i++)
if(elm[i].type==”checkbox” &&
elm[i].id!=theBox.id)
{
//elm[i].click();

if(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;

}
}

//User for check any checkbox is selected or not and delete confirm message
function checkDelete(spanChk)
{
var chks=document.getElementsByTagName(‘input’);
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert(“Please select at least one checkbox..!”);
return false;
}
else
{
if(confirm(“r u sure delete records?”))
{
return true;
}
else
{
return false;
}
}
}
</script>

–GridView .aspx page–

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” OnRowDeleting=”GridView1_RowDeleting” ShowFooter=”True”>
<Columns>
<asp:TemplateField HeaderText=”Select”>
<HeaderTemplate>
<input id=”chkAll” type=”checkbox” runat=”Server” onclick=”javascript:SelectAllCheckboxes(this);” />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID=”checkbox1″ runat=”Server” />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Rollno”>
<ItemTemplate>
<asp:Label ID=”lblRollno” runat=”server” Text='<%# Eval(“rollno”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Name”>
<ItemTemplate>
<asp:Label ID=”lblName” runat=”server” Text='<%# Eval(“name”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”City”>
<ItemTemplate>
<asp:Label ID=”lblCity” runat=”server” Text='<%# Eval(“city”) %>’></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID=”lbnDelete” CommandName=”Delete” runat=”server” Text=”Delete”
OnClientClick=”javascript:return checkDelete(this);”></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID=”btnSubmit” runat=”server” Text=”Delete Selected” OnClick=”btnSubmit_Click”
OnClientClick=”javascript:return checkDelete(this);”  />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

—aspx.cs page—

Single Record Delete Coding From Gridview

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label rno = (Label)GridView1.Rows[e.RowIndex].FindControl(“lblRollno”);
int no = Convert.ToInt32(rno.Text);

string str = “delete from tybca where rollno=” + no;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[“TESTConnectionString”].ToString());
conn.Open();
SqlCommand cmd = new SqlCommand(str, conn);
cmd.ExecuteNonQuery();
BindGrid();
}

Multiple Selected Checkbox Record Deleteing Coding

protected void btnSubmit_Click(object sender, EventArgs e)
{
ArrayList chkList = new ArrayList();
Label rollno;
int rno;

//Find Multiple checkbox was checked

for(int row=0; row<GridView1.Rows.Count;row++)
{
CheckBox c = (CheckBox)GridView1.Rows[row].Cells[0].FindControl(“CheckBox1”);
if (c.Checked != null)
{
if (c.Checked)
{
rollno = (Label) GridView1.Rows[row].Cells[1].FindControl(“lblRollno”);
rno = Convert.ToInt32(rollno.Text);
chkList.Add(rno);
}
}
}

//Delete Multiple Records
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[“TESTConnectionString”].ToString());
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
string strSql;
foreach (int i in chkList)
{
//Response.Write(i);
strSql = “Delete from tybca where rollno=” + i;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql;
cmd.ExecuteNonQuery();
}
BindGrid(); //this function bind gridview with records from datasource
}

Joins in SQL Server

Inner Joins

It match records together based on one or more common fields, as do most JOINS but inner joins return only records where there are matches for whatever fields you have said are to be used for join.

Join Two Tables

Table_1 : Product_Master

product_master

Table_2 : Sales_Order_Detaisl

sales_order_details

Query:

select a.product_no,a.decscription from product_master a
inner join sales_order_details b on a.product_no = b.product_no

Multiple Inner Joins

select a.product_no,a.decscription,d.name from product_master a
inner join sales_order_details b on a.product_no = b.product_no
inner join sales_order c on b.s_order_no = c.s_order_no
inner join client_master d on c.client_no = d.client_no
where d.name=’Ivan Bayross’

Outer Joins

Syntax: Select * from left_table_name <LEFT or RIGHT>  OUTER  JOIN right_table_name on <condition>

Example

select a.product_no from product_master a
left outer join sales_order_details b on
a.product_no = b.product_no

It will display all records of left, it does not important to find matches with right table. And it does not display right table records which are not match found

CROSS Join

A cross join is differ from other joins in that there is no ON operator and that it joins every record on one side of the JOIN with every record on the other side of the JOIN.

Syntax : Select * from left_table_name cross join right_table_name

It will display possibility of matching records in both tables. Suppose LEFT table have 3 records and right table 5 then Cross join display 3*5=15 records, match possibilities.

Find Tables List Structure Count Duplicate Records

use <database_name>

Select DataBase using above query

select * from information_schema.tables

You can easily fine tables list using above syntax.

sp_help <table_name>

See particular table structure/Design.

select s_order_no, count(s_order_no) As ‘SalesOrder’ from sales_order_details group by s_order_no having (count(s_order_no)>1)

Find Duplicate Records In Table

Java Script Validation onSubmit event of form

<script language=”javascript” type=”text/javascript”>
function validateFormOnSubmit(theForm)
{
var reason = “”;
var intFlag = 0;
//Radio button List validation
reason += validateTextBox();
reason += validateLastName();
reason += validateDate();
reason += validateQualification();
reason += validateRadioButtonList();

if(reason != “”)
{
//alert(“Please select Student Status”);
alert(reason);
return false;
}
else
{
return true;
}
/* complete radio list validation */
}

function validateTextBox()
{
var listItemArray = document.getElementById(‘txtFirstName’).value;
var intIsItemChecked = “”;
if(listItemArray.length==0)
{
intIsItemChecked = “First name is required.\n”;
}
return intIsItemChecked;
}

function validateLastName()
{
var listItemArray = document.getElementById(‘txtLastName’).value;
var intIsItemChecked = “”;
if(listItemArray.length==0)
{
intIsItemChecked = “Last name is required.\n”;
}
return intIsItemChecked;
}

function validateDate()
{
var listItemArray = document.getElementById(‘txtBirthDate’).value;
//alert(listItemArray);
var intIsItemChecked = “”;
if(listItemArray.length==0)
{
intIsItemChecked = “Birth date is required.\n”;
}
return intIsItemChecked;
}

function validateQualification()
{
var elementRef = document.getElementById(‘chlEducaionalQualification’);
var listItemArray = elementRef.getElementsByTagName(‘input’);

var intIsItemChecked = “Please select education qualification.\n”;

for (var i=0; i<listItemArray.length; i++)
{
var listItem = listItemArray[i];

if ( listItem.checked )
{
intIsItemChecked = “”;
break;
}
}
return intIsItemChecked;
}

function validateRadioButtonList()
{
var listItemArray = document.getElementsByName(‘rdlStudentStatus’);
var intIsItemChecked = “Please select student status.\n”;

for (var i=0; i<listItemArray.length; i++)
{
var listItem = listItemArray[i];
if ( listItem.checked )
{
intIsItemChecked = “”;
break;
}
}
return intIsItemChecked;
}
</script>

write javascript function name on form’s on submit event..

<form id=”frmStudentEnquiry” runat=”server” onsubmit=”return validateFormOnSubmit(this)>

links

link for Prevent Server Files to delete from client pc

http://www.bigresource.com/ASP-prevent-my-client-to-delete-file-yAVtPdFN.html

Gridview

Gridview Dynamically Insert Update Deleted.

http://csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource-insert-edit.html

2 list box item transfer together

Add Item into ListBox

Write below code in page load event for adding items in listbox1

if (!Page.IsPostBack)
{
ListBox1.Items.Add(“Baroda”);
ListBox1.Items.Add(“Anand”);
ListBox1.Items.Add(“Ahmedabad”);
ListBox1.Items.Add(“Pune”);
}

Now create another list box and one button to transfer multiple selected item from previous listbox

Write downbelow code in Button Click event………..

int sel = 0;

for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
sel = sel + 1;
}
}

if (sel == 1)
{
ListBox2.Items.Add(ListBox1.SelectedItem.Value);
ListBox1.Items.Remove(ListBox1.SelectedItem.Value);

}
else
{
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
ListBox2.Items.Add(ListBox1.Items[i].Value);

}
}

for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
ListBox1.Items.RemoveAt(i);
i = i – 1;
}
}
}

when selected items transfer from Listbox1, they are deleted also.

For remove all items of listbox

ListBox1.Items.Clear();

Asp.Net

What is .net?

.net framework is a programming paltform that is used to developing windows and web based software. It has number of pre-coded solutions that manage the execution of programs written specially for the framework.

.net framework has 2 main parts.

  1. Common language runtime
  2. Class library

The code of a program is compiled into Microsoft Intermediate Language (MSIL) and stored in a file called assembly. The assembly is then compiled by the CLR to native code at run-time.

The CLR (commong language runtime) has many features such as memory management, code execution, error handling, code safety verification and garbage collection. Thus appliction run under the CLR are called manage code.

How does classes are organized in .net framework?

The .Net framework has organized its classes using namespace.

The common namespace are

System System.Runtime
System.Collections System.Security
System.Configuration System.ServiceModel
System.Data System.Text
System.Diagnostics System.Threading
System.Drawing System.Web
System.IO System.Windows
System.Linq System.Workflow.*
System.Net System.Xml

What are the ways to persistent data in a web application?

Data can be persisted in the web application using any of the following mechanism.

Application State, View State, Session State

What are the different types of exceptions – handling approaches in Asp.Net web application?

Try , Catch and Finally keyword for VB, try , catch and finally for C#. Error event procedure at the Globale, Page level and Application.

Describe the purpose of error pages and why they needed.

Error page is used to trap the exceptions occur outside the scope of appliction. The exceptions of these types are identified by HTTP response code. These exceptions are handle by IIS by displaying custome error pages listed in your applications web.config.

DataSet.Clone Vs DataSet.Copy

DataSet clone copies the structure only whereas data set copy copies the structure and data.

Explain how to remove anonymous access to the IIS web application.

  1. <configuration>                                                                                                                                                                     <system.web>                                                                                                                                                                          <authorization>                                                                                                                                                                            <deny  user=?>                                                                                                                                                                      <configuration>                                                                                                                                                                    <system.web>                                                                                                                                       <authorization>

How to create custom control in Asp.Net 2.0?

Then you can add any server control like Textbox, Label, and Button etc… any you may add your functionality as your requirement. Then you build the solution, after build successfully you will get corresponding dll file in debug folder.

Then create web application, right click on Toolbox at any tab select choose items.. then you will get choose Toolbox item window, in that  window select .Net framework components Tab, then click on browse and navigate the files you have previously created then select dll file and click open button then click ok button then you will get the custom control in Toolbox at corresponding tab, then you may use the control as general server control.

Life Cycle of Asp.Net web Form

Page init, Page load, Page PreRender, Page unload, Page dispose, Page error

Define Process, Session and Cookies.

Process – Instance of the application, Session – Instance of the user accessing application, Cookie – It is used to store amount of data on Client Computer.

What is Assembly? Explain it parts?

  1. An assembly exists as .DLL and .EXE that contain MSIL code that is executed by CLR. An assembly contains interface and classes, it can also contain resources like bitmaps, files etc. It carries version details which are used by CLR during execution. Two assemblies                of the same name but with different versions can run side-by-side enabling application that depends on a specific version to use assembly of that version. An assembly is the unit on which permission are generated. It may be private or global. Private assembly used by only those applications which belongs it. And Global assembly used by any application of system.

Parts of Assembly.

Assembly Manifest – it contains version name etc.  , Type Metadata – it contains MSIL  code, Resources

Admin Editor

How to use FCK Editor For Insert Update Delete Text Dynamically?

1. Download FCK Editor From: http://www.fckeditor.net/download

2. Unpack download files. There you will find the original source code of the control and a compiled version of it. The file is called FredCK.FCKeditorV2.dll.

  • bin/Release/1.1/ – the version designed for ASP.NET 1.1
  • bin/Release/2.0/ – the version designed for ASP.NET 2.0

You most probably will not need to make changes in the source, so just consider the compiled DLL file, and just create a reference to it in your project. You have two options to do that:

  1. Manually copy the FredCK.FCKeditorV2.dll file to the “bin” directory of your web site.
  2. Right-click “References” in your Visual Studio.NET project in the “Solution Explorer”. Use “Browse” to select the FredCK.FCKeditorV2.dll file from the directory you have saved it in.

You can include the control in your Visual Studio.NET controls toolbox. Just right-click on it and select “Choose Items”. Then, just point to the FredCK.FCKeditorV2.dll file by using the “Browse” option. Remember to make sure that you have the latest version of the dll. It may be worthwhile to recompile from the source if you are having issues getting the upload and connector features to work.

Note: Download full version fck editor with js files and add that folder in your website after that set it as Basepath property of fck tag .aspx page.