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
I want to connect a system in LAN and I want to access that. Whenever I am moving a mouse in my desktop, the similar thing has to happen in another system in which I have connected. I need coding for this in C# and ASP.NET Can anyone please help me. It is very urgent. Thanks in advance. My email id is manojkumarchallagundla@gmail.com Will you please?
How many types of cache are there?
What are the advantages and disadvantages of Using Cookies?
How to count the number of objects present in a web page? How to count the number of radio buttons in a web page?
What is a 1x1 pixel?
What language does asp.net use?
What is the difference between the get method () and post method ()?
How many validators do ASP.NET have?
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.
Suppose You Want A Certain Asp.net Function Executed On Mouseover For A Certain Button. Where Do You Add An Event Handler?
Explain what is viewstate?
What is a 404 redirect?
What is content place holder?
What are sharepoint pages?
Explain how asp.net page works?