What is the difference between Server.Transfer and
Response.Redirect? Why would you choose one over the other?
Answer Posted / d
/* Default.aspx */
<div>
<asp:DropDownList ID="ddlProject" runat="server"
AutoPostBack="true"></asp:DropDownList>
<asp:DropDownList ID="ddlDivision" runat="server"
AutoPostBack="true"></asp:DropDownList>
<asp:GridView ID="gvMember" runat="server"
AutoGenerateColumns="false"
OnRowDataBound="gvMember_RowDataBound">
<Columns>
<asp:BoundField DataField="ProjDesc"
HeaderText="Project Name" />
<asp:BoundField DataField="DivisionName"
HeaderText="Division Name" />
<asp:BoundField DataField="MemberID" HeaderText="Member
ID" />
<asp:BoundField DataField="MemberName"
HeaderText="Member Name" />
</Columns>
</asp:GridView>
</div>
/* Default.aspx.cs */
using System;
using System.Data;
using System.Configuration;
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.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public string projDesc = string.Empty;
public string divisionName = string.Empty;
protected void Page_Load(object sender, EventArgs e) {
string projCode = string.Empty;
string divisionID = string.Empty;
if (!IsPostBack) {
PopulateData.LoadProject(ddlProject);
}
projCode = ddlProject.SelectedValue.ToString();
if (Session["projCode"] == null || !projCode.Equals
(Session["projCode"].ToString())) {
PopulateData.LoadDivision(ddlDivision,
projCode);
Session["projCode"] = projCode;
}
divisionID = ddlDivision.SelectedValue.ToString();
if (!divisionID.Equals(string.Empty)) {
gvMember.DataSource =
PopulateData.LoadMemberDetails(projCode, divisionID);
gvMember.DataBind();
}
}
protected void gvMember_RowDataBound(object sender,
GridViewRowEventArgs e) {
if (e.Row.RowIndex == 0) {
projDesc = e.Row.Cells[0].Text;
divisionName = e.Row.Cells[1].Text;
}
if (e.Row.RowIndex > 0) {
if (projDesc.Equals(e.Row.Cells[0].Text)) {
e.Row.Cells[0].Text = "";
}
if (divisionName.Equals(e.Row.Cells[1].Text)) {
e.Row.Cells[1].Text = "";
}
}
}
}
/* Populate.cs */
using System;
using System.Data;
using System.Configuration;
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;
/// <summary>
/// Summary description for PopulateData
/// </summary>
public class PopulateData
{
public PopulateData()
{
//
// TODO: Add constructor logic here
//
}
public static DataSet LoadProject() {
string query = string.Empty;
query = "select * from Project";
DataSet dst = Data.getDataSet(query);
return dst;
}
public static void LoadProject(DropDownList ddlProject)
{
string query = string.Empty;
query = "select * from Project";
DataSet dst = Data.getDataSet(query);
ddlProject.DataSource = dst;
ddlProject.DataValueField = dst.Tables[0].Columns
["ProjCode"].ToString();
ddlProject.DataTextField = dst.Tables[0].Columns
["ProjDesc"].ToString();
ddlProject.DataBind();
dst.Dispose();
}
public static DataSet LoadDivision(string projCode) {
string query = string.Empty;
query = "select * from Division where ProjCode = "
+ Convert.ToInt32(projCode);
DataSet dst = Data.getDataSet(query);
return dst;
}
public static void LoadDivision(DropDownList
ddlDivision, string projCode) {
string query = string.Empty;
query = "select * from Division where ProjCode = "
+ Convert.ToInt32(projCode);
DataSet dst = Data.getDataSet(query);
ddlDivision.DataSource = dst;
ddlDivision.DataValueField = dst.Tables[0].Columns
["DivisionID"].ToString();
ddlDivision.DataTextField = dst.Tables[0].Columns
["DivisionName"].ToString();
ddlDivision.DataBind();
dst.Dispose();
}
public static DataSet LoadMemberDetails(string
projCode, string divisionID) {
string query = string.Empty;
query = "select c.ProjDesc, b.DivisionName,
a.MemberID, a.MemberName from Member a";
query += " inner join Division b on a.DivisionID =
b.DivisionID";
query += " inner join Project c on b.ProjCode=
c.ProjCode";
query += " where a.ProjCode = " + Convert.ToInt32
(projCode) + " and a.DivisionID = " + Convert.ToInt32
(divisionID);
DataSet dst = Data.getDataSet(query);
return dst;
}
}
/* Connection.cs */
using System;
using System.Data;
using System.Configuration;
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.Data.SqlClient;
/// <summary>
/// Summary description for Connection
/// </summary>
public class Connection
{
public Connection()
{
//
// TODO: Add constructor logic here
//
}
public static SqlConnection OpenConnection
(SqlConnection con) {
con.ConnectionString =
ConfigurationManager.ConnectionStrings["conString"].ToString
();
con.Open();
return con;
}
public static void CloseConnection(SqlConnection con){
if (con.State == ConnectionState.Open) {
con.Close();
}
}
}
/* Data.cs */
using System;
using System.Data;
using System.Configuration;
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.Data.SqlClient;
/// <summary>
/// Summary description for Data
/// </summary>
public class Data
{
public Data()
{
//
// TODO: Add constructor logic here
//
}
public static DataSet getDataSet(string query) {
SqlConnection con = new SqlConnection();
DataSet dst = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(query,
Connection.OpenConnection(con));
dap.Fill(dst);
Connection.CloseConnection(con);
return dst;
}
}
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Define page output caching?
Is asp.net easy to learn?
To wrap up a call to a Web service the standard used is..?
What can you do with asp.net?
Why session is used in asp.net?
What is the concept of view state in asp.net?
When does a session actually start?
What is asp.net architecture?
What is the namespace to create thread in .net?
What is session state server?
Can you set which type of comparison you want to perform by the comparevalidator control?
What are type/key pairs in client script registration?
What are the new web part controls in asp.net 2.0 ?
a web application needs to be created to accept the product name and quantity of a toy from a customer. After the customer has entered the product name the application needs to display the discounted price of the product to the customer (company is offering 35% discount on all products). The application should allow the customer to select the product name from a list box. and also while i'm data binding to a label with custom data binding with some declarations : "The Discounted Price is "+((System.Convert.todouble(lblprodprice.text)*(system.convert.todouble(txtqty.text)) - ((System.convert.todouble(lblprodprice.text)*(system.convert.todouble(txtqty.text)*0.35)). Where i need to give this declaration in asp.net 2.0.
How to include silver light .xap page into asp.net web application and what is the purpose of using silverlight application?