SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["erp"].ConnectionString);
con.Open();
string intero = "Select * from judete";
SqlCommand cmd = new SqlCommand(intero, con);
SqlDataReader rdr;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
CheckBoxList check = new CheckBoxList();
check.Visible = true;
check.Text = rdr[1].ToString() + "<br/>";
Panel1.Controls.Add(check);
}
I have the above code that brings up data from table "Judet" and for each row a checkbox. Now I want when I check a checkbox say USA I want to bring data from another table "Localitati" that will display cities from USA.How can I do that? I'm using c# in an asp.net application.
...
string sqlStatement = "Select * from Localitati";
if (cbUS.IsChecked)
{
sqlStatement += " WHERE country = 'USA' ";
}
else if (cbOtherCountry.IsChecked)
{
sqlStatement += " WHERE country = 'OtherCountry' ";
}
Use the OnCheckedChanged event for checkBox.....
CheckBox on an ASP.NET Content Form like
<asp:CheckBox runat="server" ID="chkTest" AutoPostBack="true" OnCheckedChanged="chkTest_CheckedChanged" />
In code behind, keep the following code:
protected void chkTest_CheckedChanged(object sender, EventArgs e)
{
//do action here
}
Related
I am new to C# and am trying to learn how I would be able to change the contents of one drop down list upon the change of another? My current attempt as shown below was unsuccessful, so any advice or help would be appreciated.
protected void drpDwnSchool_TextChanged(object sender, EventArgs e)
{
drpDwnTeacher.Items.Clear();
string selectedSchool = drpDwnSchool.SelectedValue.ToString();
String sqlQueryTeacher = "SELECT * FROM Teacher WHERE SchoolName = '" + selectedSchool + "'";
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["Lab1"].ToString());
SqlCommand sqlCommand1 = new SqlCommand();
sqlCommand1.Connection = sqlConnect;
sqlCommand1.CommandType = CommandType.Text;
sqlCommand1.CommandText = sqlQueryTeacher;
sqlConnect.Open();
SqlDataReader queryResultsTeacher = sqlCommand1.ExecuteReader();
while (queryResultsTeacher.Read())
{
string LastName = queryResultsTeacher["LastName"].ToString();
drpDwnTeacher.Items.Add(queryResultsTeacher["LastName"].ToString());
}
sqlConnect.Close();
}
Is it not populating the second list? if so try the "SelectedIndexChanged" event instead of text changed.
Ok, a few issues.
So, on page load, we assume you load up the first drop down.
if (IsPostBack == false)
{
// first time page load schools
LoadSchools();
}
And our code to load the combo box:
public void LoadSchools()
{
string strSQL = "SELECT SchoolName FROM tblSchools ORDER BY SchoolName";
this.DropDownSchools.DataSource = Myrst(strSQL);
this.DropDownSchools.DataBind();
}
So, on the page load, the above fills out the dropdown (combo) with the list of Schools.
Now, when you select a School?
Well, first, you need to set auto-past back for the school combo box.
Now, when a School is selected, you can now display teachers.
I would use the selected index changed, not the text change like you have.
So, that code would look like:
protected void DropDownSchools_SelectedIndexChanged(object sender, EventArgs e)
{
string strSQL;
strSQL = "SELECT Teacher from Teachers WHERE School = '" +
DropDownSchools.SelectedValue + "' ORDER BY Teacher";
DropDownTeachers.DataSource = MyRst(strSQL);
DropDownTeachers.databind();
}
And since for every sql query you have to write for the next 10 years, and create the cmd object, the connect object and the datatable object? Well, lets save some fingers, and you can use a public routine placed in your app_code or where ever you are placing your global wide code. That routine would look like:
public DataTable Myrst(string strSQL, string strCon = "")
{
// this also allows one to pass custom connection string
// - if not passed, then default
if (strCon == "") {
strCon =
ConfigurationManager.ConnectionStrings("WebEasy.My.MySettings.Test3").ConnectionString;
}
SqlConnection mycon = new SqlConnection(strCon);
SqlDataAdapter oReader = new SqlDataAdapter();
DataTable rstData = new DataTable();
oReader.SelectCommand = new SqlCommand(strSQL, mycon);
try
{
oReader.Fill(rstData);
return rstData;
}
catch
{
return null;
}
}
My c# is a bit weak but the above should work.
However, we should be using parameters for this. While dropdowns are not really direct user input, as a future habit, the above code should be using parameters and not string concatenation for the sql.
What works well is to modify the above MyRst to take a sql command object in place of a string, but the above is a good start as to how you can get this type of code to work.
I think the simplest way will be to set the Dropdownlist DataTextField from the HTML source as follows
<asp:DropDownList ID="DropDownList1" DataTextField="YourFieldNameHere" runat="server" />
And also make sure that AutoPostBack is set to true on the Dropdownlist you intend to use for populating the second Dropdownlist.
While on codebehind, bind the Dropdownlist to database as below
protected void drpDwnSchool_TextChanged(object sender, EventArgs e)
{
string selectedSchool = drpDwnSchool.SelectedValue.ToString();
String sqlQueryTeacher = "SELECT * FROM Teacher WHERE SchoolName = '" + selectedSchool + "'";
SqlConnection sqlConnect = new SqlConnection(WebConfigurationManager.ConnectionStrings["Lab1"].ToString());
SqlCommand sqlCommand1 = new SqlCommand();
sqlCommand1.Connection = sqlConnect;
sqlCommand1.CommandType = CommandType.Text;
sqlCommand1.CommandText = sqlQueryTeacher;
sqlConnect.Open();
SqlDataReader queryResultsTeacher = sqlCommand1.ExecuteReader();
if(queryResultsTeacher.HasRows){
DropDownList1.DataSource = queryResultsTeacher;
DropDownList1.DataBind();
}
sqlConnect.Close();
}
Here is my program:
What I want to do: when I enter 1 in ProductID textbox, I want category, name and price for ProductID = 1 to be filled into their textboxes.
I have tried to read from product table where ProductID = ProductIDTB.Text and then changed the other textboxes to show the data inside the other columns
Here is my code when ProductID textbox is changed:
protected void ProductIDTB_TextChanged(object sender, EventArgs e)
{
string connectionString1;
SqlConnection cnn1;
connectionString1 = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Greenwich_Butchers;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
cnn1 = new SqlConnection(connectionString1);
string selectSql1 = "SELECT * FROM [Product] WHERE ProductID = ('" + Convert.ToInt32(ProductIDTB.Text) + "') ";
SqlCommand com1 = new SqlCommand(selectSql1, cnn1);
try
{
cnn1.Open();
using (SqlDataReader read = com1.ExecuteReader())
{
while (read.Read())
{
String productcategory = Convert.ToString(read["ProductCategory"]);
ProductCategoryTB.Text = productcategory;
String productname = Convert.ToString(read["ProductName"]);
ProductNameTB.Text = productname;
String productprice = Convert.ToString(read["ProductPrice"]);
ProdPriceTB.Text = productprice;
}
}
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
finally
{
cnn1.Close();
}
}
Work-around: as textbox_textchanged event was not working, I decided to add a button which finds product using the ID:
protected void FindProductBtn_Click(object sender, EventArgs e)
{
string connectionString1;
SqlConnection cnn1;
connectionString1 = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Greenwich_Butchers;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
cnn1 = new SqlConnection(connectionString1);
string selectSql1 = "SELECT * FROM [Product] WHERE ProductID = (" + Convert.ToInt32(ProductIDTB.Text) + ") ";
SqlCommand com1 = new SqlCommand(selectSql1, cnn1);
try
{
cnn1.Open();
using (SqlDataReader read = com1.ExecuteReader())
{
while (read.Read())
{
String productcategory = Convert.ToString(read["ProductCategory"]);
ProductCategoryTB.Text = productcategory;
String productname = Convert.ToString(read["ProductName"]);
ProductNameTB.Text = productname;
String productprice = Convert.ToString(read["ProductPrice"]);
ProdPriceTB.Text = productprice;
}
}
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
finally
{
cnn1.Close();
ProductCategoryTB.ReadOnly = true;
ProductNameTB.ReadOnly = true;
ProdPriceTB.ReadOnly = true;
}
}
Set the textbox's AutoPostBack attribute to true
More info: https://meeraacademy.com/textbox-autopostback-and-textchanged-event-asp-net/
<asp:TextBox ID="ProductIDTB" runat="server" AutoPostBack="True"
OnTextChanged="ProductIDTB_TextChanged"></asp:TextBox>
By the way, use SqlParameter to use parameterized query. Aside from sql-injection attack prevention, parameterized query can help the RDBMS store and re-use the execution plan of similar queries, to ensure better performance. See: https://dba.stackexchange.com/questions/123978/can-sp-executesql-be-configured-used-by-default
string selectSql1 = "SELECT * FROM [Product] WHERE ProductID = #productIdFilter";
int productIdFilter = Convert.ToInt32(ProductIDTB.Text);
SqlCommand com1 = new SqlCommand(selectSql1, cnn1);
com1.Parameters.AddWithValue("productIdFilter", productIdFilter);
OnTextChanged Event in Code Behind
protected void txtProductId_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["_connect"].ToString());
int ProductId = Convert.ToInt32(txtProductId.Text);
SqlCommand com = con.CreateCommand();
com.CommandText = "sp_ProductGetData";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("#Mode", 1);
com.Parameters.AddWithValue("#ProductId", ProductId);
con.Open();
SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
txtProductCategory.Text = Convert.ToString(dr["ProductCategory"]);
txtProductName.Text = Convert.ToString(dr["ProductName"]);
txtPrice.Text = Convert.ToString(dr["Price"]);
}
else
{
ScriptManager.RegisterClientScriptBlock((Page)(HttpContext.Current.Handler), typeof(Page), "alert", "javascript:alert('" + Convert.ToString(("No Record Found with Prodcut Id: "+ProductId)) + "');", true);
return;
}
con.Close();
}
Stored Procedure
CREATE PROCEDURE sp_ProductGetData
(
#Mode INT=NULL,
#ProductId INT=NULL
)
AS
BEGIN
IF(#Mode=1)
BEGIN
SELECT ProductCategory,ProductName,Price FROM Product
WHERE ProductId=#ProductId
END
END
I'm having an issue with a DropDownList dispaying student names. For some reason it loses items after I click a button, which is used for giving them a grade. I'd like to find a way to preserve these items. The button does not, in any way, filter the students displayed. The resulting DropDownLists should also have autopostback set as true. The student names are not retrieved or altered in the code behind so I'm unsure why the names are disappearing from this DropDownList. Any hints/solutions would be welcome. Update: I have attached code from the front end and also code from the .cs file for the button that sends the mark for the student. After entering a score and going back to the module it was entered for the items disappearing problem arises.
<asp:SqlDataSource
ID="SQLStudentList"
runat="server"
ConnectionString="<%$ ConnectionStrings:UniString %>"
SelectCommand="SELECT DISTINCT students_profile.user_id, (first_name + ' ' + last_name ) AS studentDetails FROM students_profile INNER JOIN classlist ON students_profile.user_id = classlist.user_id INNER JOIN class ON class.class_id = classlist.class_id INNER JOIN student_module_grade ON classlist.classlist_id = student_module_grade.classlist_id INNER JOIN student_module_repeat_grades ON student_module_grade.classlist_id = student_module_repeat_grades.classlist_id WHERE class.pathway_year_id = #idpathway AND student_module_grade.module_on_pathway_id =#modpwayid OR student_module_repeat_grades.module_on_pathway_id=#modpwayid">
<SelectParameters>
<asp:ControlParameter Name="idpathway" ControlID="degreeProgDropDown" Type="String"/>
<asp:ControlParameter ControlID="modDropDown" Name="modpwayid" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="StudentsList"
OnSelectedIndexChanged="StudentsList_SelectedIndexChanged"
runat="server"
width="420"
AutoPostBack="true"
EnableViewState="true"
DataSourceID="SQLStudentList"
DataTextField="studentDetails"
DataValueField="user_id">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
{
////If there are no students the message below will be displayed
ListItem selectedItem = StudentsList.SelectedItem;
if (selectedItem != null && !String.IsNullOrEmpty(selectedItem.Text))
{
}
else
{
changedFlag.Visible = true;
changedFlag.Text = "There are currently no grades to change for any students for this module on this pathway";
changedFlag.ForeColor = System.Drawing.Color.Red;
EnterFinalMark.Visible = false;
finalMarkAssignment.Visible = false;
submitAssignmentMark.Visible = false;
repeatSubmitAssignmentMark.Visible = false;
}
if (!IsPostBack)
{
StudentsList.DataSource = SQLStudentList;
StudentsList.DataBind();
String userName = Session["UserLoggedOn"].ToString();
String conString = WebConfigurationManager.ConnectionStrings["UniString"].ConnectionString;
SqlConnection myCon = new SqlConnection(conString);
myCon.Open();
String pathwaySelectionQuery = "SELECT pathway_years.id, pathway_years.pathway_year, pathway FROM pathways INNER JOIN pathway_years ON pathways.id = pathway_years.pathway_id";
SqlCommand pathwaySelectionQuerycmd = new SqlCommand(pathwaySelectionQuery, myCon);
SqlDataReader pwayReader = pathwaySelectionQuerycmd.ExecuteReader();
while (pwayReader.Read())
{
//Put pathway year id in this table instead
degreeProgDropDown.Items.Add(new ListItem(pwayReader["pathway_year"] + ": " + pwayReader["pathway"].ToString(), pwayReader["id"].ToString()));
}
myCon.Close();
}
}
protected void repeatSubmitAssignmentMark_Click(object sender, EventArgs e)
{
String connectionString = WebConfigurationManager.ConnectionStrings["UniString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
String repeatModgradeID = "SELECT repeat_module_grade_id from student_module_repeat_grades WHERE module_on_pathway_id = '" + modDropDown.SelectedValue + "'";
SqlCommand repeatModuleGradeIDCommand = new SqlCommand(repeatModgradeID, myConnection);
Int32 repeatModGradeIDResult = Convert.ToInt32(repeatModuleGradeIDCommand.ExecuteScalar().ToString());
String repeatFindUserID = "SELECT classlist_id from classlist WHERE user_id = '" + StudentsList.SelectedValue + "'";
SqlCommand repeatFindUserIDCommand = new SqlCommand(repeatFindUserID, myConnection);
Int32 repeatClasslistval = Convert.ToInt32(repeatFindUserIDCommand.ExecuteScalar().ToString());
String modOnPwayValue = modDropDown.SelectedValue;
String repeatGrade = finalMarkAssignment.Text;
Int32 repeatGradeval = Convert.ToInt32(repeatGrade);
//Grade is a pass if it is equal to or greater than 40- otherwise it is a fail
if (repeatGradeval >= 40)
{
//Pass assigned to the string which will be added to the table
String passOrFail = "Pass";
//Assigned to label
pOrF.Text = passOrFail;
}
else
{
//Fail assigned to the string which will be added to the table
String passOrFail = "Fail";
//Assigned to label
pOrF.Text = passOrFail;
}
if (repeatGradeval >= 0 && repeatGradeval <= 100)
{
changedVAL.Visible = false;
SqlCommand addAssignmentGradeCommand = new SqlCommand("UPDATE student_module_repeat_grades SET classlist_id=#repeatClasslistid,module_on_pathway_id=#modOnPwayValue,grade=#grade,result_code=#PF,changed=1 WHERE module_on_pathway_id = '" + modDropDown.SelectedValue + "'", myConnection);
addAssignmentGradeCommand.Parameters.AddWithValue(#"modOnPwayValue", modOnPwayValue);
addAssignmentGradeCommand.Parameters.AddWithValue(#"repeatClasslistid", repeatClasslistval);
addAssignmentGradeCommand.Parameters.AddWithValue(#"grade", repeatGradeval);
addAssignmentGradeCommand.Parameters.AddWithValue(#"PF", pOrF.Text);
addAssignmentGradeCommand.ExecuteNonQuery();
myConnection.Close();
success.Visible = true;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "HideLabel();", true);
success.ForeColor = System.Drawing.Color.Green;
repeatSubmitAssignmentMark.Visible = false;
}
else
{
changedVAL.Visible = true;
changedVAL.Text = "Please enter a grade between 0 and 100";
changedVAL.ForeColor = System.Drawing.Color.Red;
}
}
My initial thought it that you are likely not currently checking if a PostBack is occurring or not within the Page_Load event of your Page, which is going to cause your data to be rebound each time.
You can generally resolve this by just performing a check within the Page_Load event itself :
protected void Page_Load(object sender, EventArgs e)
{
// If it is an initial load
if(!IsPostBack)
{
// Then perform your one-time data binding here
StudentsList.DataSource = SQLStudentList;
StudentsList.DataBind();
}
// Business as usual
}
I want to be able to use this button to search oracle three times at most and after the three attempts to disable the button and use a different search. Below is my code when the button is clicked to search first. If the catch is used three times I want to be able to disable the button.
private void btnCancelSearch_Click(object sender, EventArgs e)
{
try
{
//Connect to Database
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = conn.CreateCommand();
//Define SQL Query (Select)
strSQL = "SELECT * FROM Bookings WHERE BookingNo = '" + txtCnlBookingNo.Text + "'";
cmd.CommandText = strSQL;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
txtBookingNo.Text = dr.GetValue(0).ToString();
txtBkgSurname.Text = dr.GetValue(1).ToString();
txtBkgForename.Text = dr.GetValue(2).ToString();
txtBkgContactNo.Text = dr.GetValue(3).ToString();
txtBkgStreet.Text = dr.GetValue(4).ToString();
txtBkgTown.Text = dr.GetValue(5).ToString();
txtBkgCounty.Text = dr.GetValue(6).ToString();
txtBkgCountry.Text = dr.GetValue(7).ToString();
txtBkgEmail.Text = dr.GetValue(8).ToString();
cboBkgNoGuests.Text = dr.GetValue(9).ToString();
cboBkgPayment.Text = dr.GetValue(10).ToString();
dtpBkgCheckIn.Text = dr.GetValue(11).ToString();
dtpBkgCheckOut.Text = dr.GetValue(12).ToString();
}
catch
{
//Display confirmation message
MessageBox.Show("Not a valid Booking No");
}
Depending on your application. You can keep track of a variable called:
int ButtonClickedCount = 0;
increment this variable everytime the button is clicked. If the click count is exceeded you notify the user or disable the button.
Not sure if this is what you trying to achieve:
Declare a variable to keep track of the number of times user have clicked, then apply your logic?
int count = 0;
private void btnCancelSearch_Click(object sender, EventArgs e)
{
if(count <3){
count++;
try
{
//Connect to Database
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = conn.CreateCommand();
//Define SQL Query (Select)
strSQL = "SELECT * FROM Bookings WHERE BookingNo = '" + txtCnlBookingNo.Text + "'";
cmd.CommandText = strSQL;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
txtBookingNo.Text = dr.GetValue(0).ToString();
txtBkgSurname.Text = dr.GetValue(1).ToString();
txtBkgForename.Text = dr.GetValue(2).ToString();
txtBkgContactNo.Text = dr.GetValue(3).ToString();
txtBkgStreet.Text = dr.GetValue(4).ToString();
txtBkgTown.Text = dr.GetValue(5).ToString();
txtBkgCounty.Text = dr.GetValue(6).ToString();
txtBkgCountry.Text = dr.GetValue(7).ToString();
txtBkgEmail.Text = dr.GetValue(8).ToString();
cboBkgNoGuests.Text = dr.GetValue(9).ToString();
cboBkgPayment.Text = dr.GetValue(10).ToString();
dtpBkgCheckIn.Text = dr.GetValue(11).ToString();
dtpBkgCheckOut.Text = dr.GetValue(12).ToString();
}
catch
{
//Display confirmation message
MessageBox.Show("Not a valid Booking No");
}
}else
{
//Implement whatever search you want here
//And disable your button here
}
}
I have been making a UI panel and have dynamic data for input to the interface.
For this I want a filter an SQL query based on user selected valus of several SQL querys.
For a prototype:
I generated the panel and got the data to appear no problems, but since I do not know how many filters I will have until I look at the first query I made the checkboxes and dropdowns on the filter dynamically.
The problem I have is I cannot access the user selected values in the dropdowns or the checkboxes.
I assigned unique ID's to each element so the fastest solution would be the c# equivalent of getElementByID?
I will post some of the code below:
protected string SQConnWhere(string TableName = "Nonya", string FieldName = "Error!!!", int i=0)
{
string ConnectionString = "real string removed";
cmdText = #"SELECT DISTINCT " + FieldName + " FROM tablenamechangedfromrealonetoprotectthe innocent";
Label myLabel = new Label();
Label myLabelA = new Label();
CheckBox myCheckBox = new CheckBox();
DropDownList myList = new DropDownList();
myList.ID = "myList" + i;
myCheckBox.ID = "myCheckBox" + i;
myLabel.ID = "myLabel" + i;
myLabelA.ID = "myLabelA" + i;
myLabel.Text = FieldName;
PlaceHolder1.Controls.Add(myLabel);
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
PlaceHolder1.Controls.Add(myList);
myCheckBox.Text = "Use This Field in Filter?";
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
try
{
SqlDataAdapter adapter = new SqlDataAdapter(cmdText, conn);
DataSet ds2 = new DataSet();
adapter.Fill(ds2);
myList.DataSource = ds2;
myList.DataTextField = FieldName;
myList.DataBind();
ViewState["Data"] = ds2;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
PlaceHolder1.Controls.Add(myCheckBox);
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
//May not need this?
//filterList.Add(FieldName);
myLabelA.Text = cmdText;
PlaceHolder1.Controls.Add(myLabelA);
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
//myCheckBox.CheckedChanged += new EventHandler(UpdatemyCheckBox);
//pnlCheckList.Controls.Add(myCheckBox);
// register the control to cause asynchronous postbacks
//ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(myCheckBox);
//Label4.Text = FieldName;
return cmdText;
}
P.S. This is my first post despite browsing the website for a long time, thanks for all the help thus far!!!
I solved it using
ManualSQConnWhere(DropDownList1, myTable, "Run_ID", CheckBox1);
ManualSQConnWhere(DropDownList2, myTable, "Job_Status", CheckBox2);
ManualSQConnWhere(DropDownList3, myTable, "Job_Plan", CheckBox3);
protected string ManualSQConnWhere(DropDownList myList, string TableNameWeb2, string FieldName, CheckBox myCheckBox)
{
string ConnectionString = "Data Source=xxxxx;Initial Catalog=xxxxx;Integrated Security=True";
cmdText = #"SELECT DISTINCT " + FieldName + " FROM " + TableNameWeb2;
DataSet dbWeb2 = new DataSet();
myList.AutoPostBack = false;
//myList.ViewStateMode = ViewStateMode.Enabled;
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
try
{
SqlDataAdapter adapter = new SqlDataAdapter(cmdText, conn);
adapter.Fill(dbWeb2);
ViewState["Data"] = dbWeb2;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
myList.AppendDataBoundItems = true;
myList.DataSource = dbWeb2;
myList.DataTextField = FieldName;
myList.Items.Add(new ListItem("<None Selected>", string.Empty));
if (dbWeb2.Tables.Count > 0)
{
myList.DataBind();
}
else
{
Label1.Text = "Error on the SQL Query" + cmdText;
return cmdText;
}
myCheckBox.Text = FieldName;
return cmdText;
}
This code propogated the dropdowns and I simply entered the tags for them