Use server side variable value in JavaScript in asp.net

Sometimes we have to use server side variable value in JavaScript. Here I would give how to use the Server Side Variable in JavaScript.

In Code behind
public string strName;

In Page_Load
strname = “Welcome to Code Behind Page”;

In java script we call the code bind variable is given below

 alert(‘<%=strname%>’);

Advertisements

How to get distinct Data from Dataset ( or) select distinct from dataset.

In some scenario select distinct data from the Dataset. Dataset provide an option to get distinct data from the dataset. I have database connection to connect my local database.


  SqlDataAdapter da = new SqlDataAdapter(“select empolyeename,Department,salary from employees inner
join department on  employees.deptid=department.deptid”
, con);

DataSet ds = new DataSet();

da.Fill(ds,“details”);


After fill the dataset we want to select distinct department from the dataset.For this use the DefaultView.ToTable()

 

GridView1.DataSource= dv.ToTable(true, “Department”);

GridView1.DataBind();

How to filter data in dataset

 

Dataset is collection of data of Tables stored in Client Memory. In some scenario we want to filter the data without submitting another request to the database server.Dataset provide an option to filter the data based on condition. 

SqlDataAdapter da = new SqlDataAdapter(“select
empolyeename,Department,salary from employees inner join department on  employees.deptid= department.deptid”
, con);
 

DataSet ds = new
DataSet();

da.Fill (ds,“details”);

 

In the dataset if there is a requirement to filter the data for particular department .For example we assume dept as “Software”.
In this case we can use Data view


 
DataView dv = new DataView();

dv=ds.Tables[“details”].DefaultView;

dv.RowFilter=“Department =’Software‘”;

GridView1.DataSource = dv;

GridView1.DataBind();