Prncesnicki
asked on
Is there a way to create a form on a button click using C# and ASP.NET?
I have a page that contains a ddl of employees from an Access DB. I have one button that grabs data from a table when an employee is selected in the ddl and the button is clicked. I want to create another button that brings up the 3 text boxes and one ddl with choices from the the table. I also want the one text box to autopopulate the ID for the selected employee and the other to autopopulate the year. Once info in selected and added, I want a submit button to update the Access DB. Is this possible or am I out of my mind?
ASKER
Can you give me a code example of a simple text box like this?
ASKER
I created everything and set them to invisible. Can you please help me with the code for clicking the button to turn these to visible?
you have a text box on the aspx page called txtName
set Visible="false" on the aspx page
when the button click happens and now you want to make the text box visible jsut add txtName.Visible = true;
set Visible="false" on the aspx page
when the button click happens and now you want to make the text box visible jsut add txtName.Visible = true;
ASKER
Actually the real problem I am having here now is figuring out how to get the button to turn the boxes visible and link the SSN text box to the selected employee in the ddl. Any clue on how to do that?
ASKER
This is all I have...
protected void New1(object sender, EventArgs e)
{
String strConn3 = "Provider=Microsoft.Jet.OLEDB.4.0; "
+ "Data Source=" + Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "/Database/Company.mdb";
String sqlSelect = "Select * "
+ "from Performance_Review "
+ "INNER JOIN Employee "
+ "ON Performance_Review.ee_ID = Employee.ssn "
+ "WHERE Employee.ssn="
+ ddlEmp.Text;
}
Here is your code for showing the textboxes with the data according to the selected value in the DropDownList
<div>
<asp:DropDownList ID="ddlEmp" runat="server">
<asp:ListItem>Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
<asp:TextBox ID="TextBox1" runat="server" Visible="false"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server" Visible="false"></asp:TextBox>
</div>
protected void Button1_Click(object sender, EventArgs e)
{
String strConn3 = "Provider=Microsoft.Jet.OLEDB.4.0; "
+ "Data Source=" + Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "/Database/Company.mdb";
SqlConnection con = new SqlConnection(strConn3);
String sqlSelect = "Select * "
+ "from Performance_Review "
+ "INNER JOIN Employee "
+ "ON Performance_Review.ee_ID = Employee.ssn "
+ "WHERE Employee.ssn="
+ ddlEmp.SelectedItem.Text;
SqlDataAdapter da = new SqlDataAdapter(sqlSelect, con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
TextBox1.Text = dt.Rows[0]["ee_ID"].ToString();
TextBox2.Text = dt.Rows[0]["ee_year"].ToString();
TextBox1.Visible = true;
TextBox2.Visible = true;
}
else
{
TextBox1.Visible = false;
TextBox2.Visible = false;
}
}
ASKER
I kept getting an error on the "SqlDataAdapter" code so I modified your code a bit and now I can view the page however when I select an employee and click button I get the following error:
No value given for one or more required parameters.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbExc eption: No value given for one or more required parameters.
No value given for one or more required parameters.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbExc
protected void Button1_Click(object sender, EventArgs e)
{
String strConn3 = "Provider=Microsoft.Jet.OLEDB.4.0; "
+ "Data Source=" + Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "/Database/Company.mdb";
String sqlSelect = "Select * "
+ "from Performance_Review "
+ "INNER JOIN Employee "
+ "ON Performance_Review.ee_ID = Employee.ssn "
+ "WHERE Employee.ssn="
+ ddlEmp.SelectedItem.Text;
OleDbConnection objConn3 = new OleDbConnection(strConn3);
OleDbCommand objCommand3 = new OleDbCommand(sqlSelect, objConn3);
OleDbDataAdapter objAdapter3 = new OleDbDataAdapter(objCommand3);
DataSet objDataSet = new DataSet();
DataTable dt = new DataTable();
objAdapter3.Fill(objDataSet, "dt");
if (dt.Rows.Count > 0)
{
eeID.Text = dt.Rows[0]["ee_ID"].ToString();
evalyr.Text = dt.Rows[1]["evaluation_year"].ToString();
eeID.Visible = true;
evalyr.Visible = true;
}
else
{
eeID.Visible = false;
evalyr.Visible = false;
}
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
or use a span and just change the visible state of the span from false to true and vice versa