Hello everyone. I am new to C#. I am trying to code an application that will show a single record in a DetailsView once that record is selected from a GridView. I understand how to create it using ObjectDataSource and SqlDataSource, but I would like to create
it programmactically w/in the C# code. Can anyone help? Thanks.
This is what I have so far. This the connection between the DropDownList control and the GridView control:
using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ...;
namespace ...
{
public partial class ... : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sql = "select distinct ... FROM ... order by ...";
using (OracleCommand command = new OracleCommand(sql, ConnectionManager.GetConnection()))
{
OracleDataReader dr = command.ExecuteReader();
tssweb
Member
10 Points
8 Posts
Gridview / Detailsview - Master Details App
Apr 05, 2012 08:16 PM|LINK
Hello everyone. I am new to C#. I am trying to code an application that will show a single record in a DetailsView once that record is selected from a GridView. I understand how to create it using ObjectDataSource and SqlDataSource, but I would like to create it programmactically w/in the C# code. Can anyone help? Thanks.
This is what I have so far. This the connection between the DropDownList control and the GridView control:
using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ...;
namespace ...
{
public partial class ... : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sql = "select distinct ... FROM ... order by ...";
using (OracleCommand command = new OracleCommand(sql, ConnectionManager.GetConnection()))
{
OracleDataReader dr = command.ExecuteReader();
ddl.DataSource = dr;
ddl.DataValueField = "...";
ddl.DataTextField = "...";
ddl.DataBind();
command.Connection.Close();
command.Connection.Dispose();
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string sql = "SELECT ... FROM ... WHERE ... = '" + ddl.SelectedValue.ToString() + "'";
using (OracleCommand command = new OracleCommand(sql, ConnectionManager.GetConnection()))
{
OracleDataAdapter da = new OracleDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
GVJobs.DataSource = ds;
GVJobs.DataBind();
}
}
}
}