aspx page:
OnSelectedIndexChanged="ddlcons" AutoPostBack="true">
style="height: 26px" />
code behind file:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.OracleClient;
public partial class ora_con : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnora_Click(object sender, EventArgs e)
{
try
{
//use your own userid,password and datasorce
string Constring;
Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
OracleConnection con = new OracleConnection(Constring);
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "CREATE TABLE con(id varchar2(20),name varchar2(50))"; // uid not null
cmd.ExecuteNonQuery();
Response.Write("");
}
catch (Exception)
{
Response.Write("");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
{
string Constring, query;
Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
OracleConnection con = new OracleConnection(Constring);
con.Open();
query = "SELECT name,id FROM con where id = '" + TextBox3.Text.Trim() + "'";
OracleCommand command = new OracleCommand(query, con);
OracleDataReader reader = command.ExecuteReader();
reader.Read();
TextBox2.Text = reader[0].ToString();
TextBox1.Text = reader[1].ToString();
reader.Close();
con.Close();
}
}
protected void ddlcons(object sender, EventArgs e)
{
if (ddlcon.SelectedValue.ToString() == "1")
{
TextBox2.Text = "";
// TextBox3.Text = "";
}
else
{
Console.WriteLine("No Changes");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
{
string Constring;
Constring = WebConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
OracleConnection con = new OracleConnection(Constring);
con.Open();
string str = "insert into con (name) values ('" + TextBox2.Text + "')";// here without clearing id will appear that id also should be insert with this name.
OracleCommand cmd = new OracleCommand(str, con);
cmd.ExecuteNonQuery();
Response.Write("Inserted");
}
}
}4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted Jul 31, 2013, 6:03 AM EDT
Please let me know, do you need sample for this?
Former memberPosted Jul 31, 2013, 6:11 AM EDT
If you're allowed to AJAX then you can use UpdatePanel. You can place the dropdownlist control inside the updatepanel so that It will not do postback.
Rajesh B22 pointsPosted Jul 31, 2013, 7:07 AM EDT
Rajesh B22 pointsPosted Jul 31, 2013, 7:09 AM EDT