PDA

View Full Version : Help with C# DDL


w4r|Ronin
09-01-2005, 10:51 PM
I am going to try and describe my situation, but please bear in mind this is my absolute FIRST time using C#.

I have a database that contains information on Software Updates for multiple products that my company makes. Each product has a number of different versions.

What I am trying to build is a web page which displays a list of software updates. The page will display updates for a specific product, and then likewise for that products specific version. (Both based on user preferences)

I have two dropdowns in my page. The first one allows the user to select a specific product. Once that product is selected, I want the value of their selection to return as a variable that is used in an MSSQL select statement which will then populate the other drop down only with the versions associated with that product.

So far, I have gotten the page to the point where when it loads…all versions for each and every product is listed in the second drop down menu. The Page Load function populates the 2nd drop down list with the product versions based on the txtSeries Selected value (which below is set to a wildcard value so it displays all)

The challenge I have is that when a different product is selected from the first dropdownlist, I cannot get the list of product versions to update based on which product the user chooses. I have toyed with using the OnSelectedIndexChange, but thus far it has not worked. Aside from that, the rest of the functions I need from the page work fine.

Below is the code. Just to note, the html sorts the results by month, which is why there is a redundant amount of DisplayData functions (one for each month). I am also curious as to why on page load, no results are displayed on the screen until a product and/or a version is selected…but that for now is not my primary concern…I just need to get these drop downs working!! TYIA!!


<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="C#" Debug="true"%>


<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{

string sNewSeries = txtSeries.SelectedItem.Value;
SqlConnection con2 = null;
SqlCommand cmd2 = null;
SqlDataReader rd2 = null;


con2 = new SqlConnection("server=SERVER;uid=USERNAME;" + "pwd=PASSWORD;database=DATABASENAME");
cmd2 = new SqlCommand("select distinct(code) from api_release where series like '" + sNewSeries + "' order by code desc", con2);

if (! this.IsPostBack)
{
con2.Open();
txtRelease.DataSource = cmd2.ExecuteReader();
txtRelease.DataTextField = "code";
txtRelease.DataValueField = "code";
txtRelease.DataBind();
con2.Close();


}

}

protected void DisplayData(string sStartDate, string sEndDate, string sRelease, string sSeries) {



SqlConnection con = null;
SqlCommand cmd = null;
SqlDataReader rd = null;



Response.Write("<table width=100% cellpadding=0 cellspacing=0 border=0><tr>");
Response.Write("<td bgcolor=gray width=50% align=left><font size=1><b>Software Update - Click to Open Update Folder on Omega</b></font></td>");
Response.Write("<td bgcolor=gray width=10% align=center><font size=1><b>README</b></font></td>");
Response.Write("<td bgcolor=gray width=10% align=center><font size=1><b>Download</b></font></td>");
Response.Write("<td bgcolor=gray width=15% align=center><font size=1><b>Link to KB Article</b></font></td>");
Response.Write("<td bgcolor=gray width=15% align=center><font size=1><b>Version</b></font></td>");
Response.Write("</tr></table>");


try {

con = new SqlConnection("server=SERVER;uid=USERNAME;" + "pwd=PASSWORD;database=DATABASENAME");
cmd = new SqlCommand("select * from vw_api_update_info where create_date between '" + sStartDate + "' and '" + sEndDate + "' and series like '" + sSeries + "' and release_code like '" + sRelease + "'", con);

con.Open();
rd = cmd.ExecuteReader();

while(rd.Read()) {
Response.Write("<table width=100% bgcolor=#C0C0C0 cellpadding=0 cellspacing=0 border=0><tr>");
Response.Write("<td width=50%><a href=file://apint/omega/qc/Version%20Release/Software%20Updates/" + sSeries + "/Released/" + rd.GetString(0) + " target=_blank><font size=1>" + rd.GetString(0) + "</a></td>");
Response.Write("<td width=10% align=center><a href=file://apint/omega/qc/Version%20Release/Software%20Updates/" + sSeries + "/Released/" + rd.GetString(0) + "/Installation%20Instructions/" + rd.GetString(0) + ".txt target=_blank><font size=1>Install Inst.</font></a></td>");
Response.Write("<td width=10% align=center><a href=file://apint/omega/qc/Version%20Release/Software%20Updates/" + sSeries + "/Released/" + rd.GetString(0) + "/" + rd.GetString(0) + ".zip target=_blank><font size=1>ZIP File</font></a></td>");
Response.Write("<td width=15% align=center><a href=http://apollo/kb/searchresults_nonorder.asp?method=exact&QueryString=%22" + rd.GetString(0) + "%22&Limit=25&SeriesID=0&SearchType=fulltext&Component=0&ArticleType= target=_blank><font size=1>Knowledge Base</font></a></td>");
Response.Write("<td width=15% align=center><font size=1 color=blue>" + rd.GetString(2) + "</td></font>");
Response.Write("</tr></table>");
Response.Write("");
}
} catch (Exception e) {
Response.Write("<p><font color=\"red\">Err: ");
Response.Write(e.Message);
Response.Write("</font></p>");
} finally {
if(rd != null)
rd.Close();
if(con != null)
con.Close();
}


}
</script>
<script language="javascript">
//<!--
var menus = new Array();
function toggleRow(element)
{

if (element.style.display == '')
{
element.style.display = 'none';
}
else
{
element.style.display = '';
}
}

//-->

</script>
<html>
<head>
<style>
body { font-family:Verdana; font-size:12pt; }
</style>
<title></title>
</head>

<body background="../../kb/images/frame/images/background.jpg" onload="">

<b><font color="#0000FF" size="6">2005 Software Updates</font></b>

<form id=Form1 runat="server">
<p><b><i>Select a Series:</i></b>
<asp:DropDownList id="txtSeries" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True" Value="%" Text=""/>
<asp:ListItem Value="PM" Text="Payrollmation"/>
<asp:ListItem Value="AS" Text="ActiveStaffer"/>
<asp:ListItem Value="NV" Text="Navigator"/>
<asp:ListItem Value="AL" Text="ActiveLink"/>
<asp:ListItem Value="SA" Text="SecurAll"/>
<asp:ListItem Value="EN" Text="Enterprise"/>
</asp:DropDownList>

<p><b><i>Select a Release:</i></b>
<asp:DropDownList id="txtRelease" runat="server" AutoPostBack="True">

</asp:DropDownList>
</p>
</form>

<div id="list" style="display:">
<font color="#FF0000"><b>
<a style="cursor:hand" onclick="toggleRow(January);">January</a></b></font><br>
<div id="January" style="display:">
<% DisplayData("01/01/2005", "01/31/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>

<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(February);">February</a></b></font><br>
<div id="February" style="display:">
<% DisplayData("02/01/2005", "02/28/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(March);">March</a></b></font><br>
<div id="March" style="display:">
<% DisplayData("03/01/2005", "03/31/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>

<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(April);">April</a></b></font><br>
<div id="April" style="display:">
<% DisplayData("04/01/2005", "04/30/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(May);">May</a></b></font><br>
<div id="May" style="display:">

<% DisplayData("05/01/2005", "05/31/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(June);">June</a></b></font><br>
<div id="June" style="display:">
<% DisplayData("06/01/2005", "06/30/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(July);">July</a></b></font><br>
<div id="July" style="display:">
<% DisplayData("07/01/2005", "07/31/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(August);">August</a></b></font><br>
<div id="August" style="display:">
<% DisplayData("08/01/2005", "08/31/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(September);">September</a></b></font><br>
<div id="September" style="display:">
<% DisplayData("09/01/2005", "09/30/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(October);">October</a></b></font><br>
<div id="October" style="display:">
<% DisplayData("10/01/2005", "10/31/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(November);">November</a></b></font><br>
<div id="November" style="display:">
<% DisplayData("11/01/2005", "11/30/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
<font color="#FF0000"><b>
<br><a style="cursor:hand" onclick="toggleRow(December);">December</a></b></font><br>
<div id="December" style="display:">
<% DisplayData("12/01/2005", "12/31/2005", Request.Form["txtRelease"], Request.Form["txtSeries"]); %>
</div>
</div>

</body>