ASP.net i have created web page using oracle db con, using a button click am fetching some data's to textbox, then after that using a drop down onselectedindexchanged event aam clearing some of the textbox values, now i have to insert the data there in the window with out clearing in the textboxes and new texts in the textboxes whixh is cleared using ddl onselect event.
<form id="form1" runat="server">
<div runat="server" id ="mydiv">
<br /> <asp:DropDownList runat="server" ID="ddlcon"
OnSelectedIndexChanged="ddlcons" AutoPostBack="true">
<asp:ListItem Value="0" Text="Select"></asp:ListItem>
<asp:ListItem Value="1" Text="Yes"></asp:ListItem>
<asp:ListItem Value="2" Text="No"></asp:ListItem>
</asp:DropDownList>
<br />
<table style="width:100%;">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnora" runat="server" Text="Create" onclick="btnora_Click" />
</td>
<td>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="search"
style="height: 26px" />
</td>
<td>
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="insert" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table> </div>
</form>
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("<script>alert('Successfully Created..');</script>");
}
catch (Exception)
{
Response.Write("<script>alert('Not Created..');</script>");
}
}
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");
}
}
}