Hi there,
How do I add an item when I'm already on Form.aspx.cs?
cboOriginalBrand.Items.Add("*"); doesn't work anymore.
Hi Maya,
This is my whole code for the program/form:
using System;using System.Collections.Generic;using Infragistics.Web.UI.ListControls; using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data;
public partial class OriginalSampleList : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { //if (Session["USERNAME"] == null) //{ // Response.Redirect("~/Login.aspx"); //}
if (Session["USERNAME"] == null) {
HttpCookie cookie = Request.Cookies["WEBPLM_USERNAME"];
if (cookie != null) {
Session["USERNAME"] = cookie.Value.ToString(); } }
if (!Page.IsPostBack) { setCombo(); }
if (Session["SQL"] != null) { sdsOriginalSamples.SelectCommand = Session["SQL"].ToString(); } grdOriginalSamples.DataBind(); }
protected void setCombo() { string strConn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ORIGSAMPLE"].ToString();
SqlConnection cn = new SqlConnection(strConn);
try { cn.Open();
string strSQL = "SELECT * FROM [qry_Original_Brands] ORDER BY 1";
SqlCommand cmd = new SqlCommand(strSQL, cn); SqlDataReader dr = cmd.ExecuteReader();
cboOriginalBrand.Items.Add(new DropDownItem() { Text = "*" });
if (dr.HasRows) { while (dr.Read()) {
cboOriginalBrand.Items.Add(new DropDownItem() { Text = dr[0].ToString() });
} }
cboOriginalBrand.NullText = "*";
dr.Close();
strSQL = "SELECT DISTINCT [Description] FROM [qry_Product_Groups] ORDER BY 1";
cmd.CommandText = strSQL; dr = cmd.ExecuteReader();
cboProductGroup.Items.Add(new DropDownItem() { Text = "*" });
if (dr.HasRows) { while (dr.Read()) { //cboProductGroup.Items.Add(dr[0].ToString()); cboProductGroup.Items.Add(new DropDownItem() { Text = dr[0].ToString() }); } }
cboProductGroup.NullText = "*";
strSQL = "SELECT * FROM [ProductType] ORDER BY 1";
cboProductType.Items.Add(new DropDownItem() { Text = "*" });
if (dr.HasRows) { while (dr.Read()) { //cboProductType.Items.Add(dr[0].ToString()); cboProductType.Items.Add(new DropDownItem() { Text = dr[0].ToString() }); } }
cboProductType.NullText = "*";
strSQL = "SELECT DISTINCT [Gender] FROM [Gender] ORDER BY 1";
cboGender.Items.Add(new DropDownItem() { Text = "*" });
if (dr.HasRows) { while (dr.Read()) { //cboGender.Items.Add(dr[0].ToString()); cboGender.Items.Add(new DropDownItem() { Text = dr[0].ToString() }); } }
cboGender.NullText = "*";
strSQL = "SELECT * FROM [qry_Designers] ORDER BY 1";
cboDesigner.Items.Add(new DropDownItem() { Text = "*" });
if (dr.HasRows) { while (dr.Read()) { //cboDesigner.Items.Add(dr[0].ToString()); cboDesigner.Items.Add(new DropDownItem() { Text = dr[0].ToString() }); } }
cboDesigner.NullText = "*";
strSQL = "SELECT * FROM [qry_Buyers] ORDER BY 1";
cboBuyer.Items.Add(new DropDownItem() { Text = "*" });
if (dr.HasRows) { while (dr.Read()) { //cboBuyer.Items.Add(dr[0].ToString()); cboBuyer.Items.Add(new DropDownItem() { Text = dr[0].ToString() }); } }
cboBuyer.NullText = "*";
strSQL = "SELECT * FROM [Borrowers] ORDER BY 1";
cboBorrower.Items.Add(new DropDownItem() { Text = "*" });
if (dr.HasRows) { while (dr.Read()) { //cboBorrower.Items.Add(dr[0].ToString()); cboBorrower.Items.Add(new DropDownItem() { Text = dr[0].ToString() }); } }
cboBorrower.NullText = "*";
dr.Close(); dr.Dispose();
strSQL = "SELECT * FROM [qry_Categories] ORDER BY 1";
cboCategory.NullText = "*";
if (dr.HasRows) { while (dr.Read()) { //cboCategory.Items.Add(dr[0].ToString()); cboCategory.Items.Add(new DropDownItem() { Text = dr[0].ToString() }); } }
cn.Close(); cn.Dispose(); } catch (Exception ex) { Response.Write(ex.Message); } }
protected void grdOriginalSamples_SelectedIndexChanged(object sender, EventArgs e) { //Response.Redirect("~/OriginalSampleForm.aspx?ORIGINALSAMPLENO=" + }
protected void grdOriginalSamples_RowDataBound(object sender, GridViewRowEventArgs e) {
//Response.Write(System.Web.VirtualPathUtility.GetDirectory());
string strHTTPLocal = GlobalVars.THUMBNAIL_PATH;
if (e.Row.RowType == DataControlRowType.DataRow) { try { Image imgFront = e.Row.FindControl("imgFront") as Image; Image imgBack = e.Row.FindControl("imgBack") as Image; Label lblOriginalSampleNo = e.Row.FindControl("lblOriginalSampleNo") as Label; HyperLink hlpSelect = e.Row.FindControl("hplSelect") as HyperLink;
hlpSelect.NavigateUrl = "~/OriginalSampleForm2.aspx?ORIGINALSAMPLENO=" + lblOriginalSampleNo.Text;
if (imgFront.ImageUrl == null || imgFront.ImageUrl == "") { imgFront.ImageUrl = "XXX"; } if (imgBack.ImageUrl == null || imgBack.ImageUrl == "") { imgBack.ImageUrl = "XXX"; }
imgFront.ImageUrl = strHTTPLocal + "?filename=" + imgFront.ImageUrl + @"&NEWWIDTH=185&MAXHEIGHT=215&ONLYRESIZEIFWIDER=true&USEDPICONVERT=false"; imgBack.ImageUrl = strHTTPLocal + "?filename=" + imgBack.ImageUrl + @"&NEWWIDTH=185&MAXHEIGHT=215&ONLYRESIZEIFWIDER=true&USEDPICONVERT=false"; } catch (Exception ex) { Response.Write(ex.Message); } } } protected void btnApply_Click(object sender, EventArgs e) { string strProductType = cboProductType.CurrentValue.Replace("*", "%"); string strProductGroup = cboProductGroup.CurrentValue.Replace("*", "%"); string strGender = cboGender.CurrentValue.Replace("*", "%");
string strBatchNumber = txtBatchNo.Text; if (txtBatchNo.Text == "") { strBatchNumber = "*"; } strBatchNumber = strBatchNumber.Replace("*", "%"); string strDesigner = cboDesigner.CurrentValue.Replace("*", "%"); string strSource = cboSource.CurrentValue.Replace("*", "%"); string strBuyer = cboBuyer.CurrentValue.Replace("*", "%"); string strBorrower = cboBorrower.CurrentValue.Replace("*", "%"); string strOriginalBrand = cboOriginalBrand.CurrentValue.Replace("*", "%"); string strCategory = cboCategory.CurrentValue.Replace("*", "");
string strSQL = "SELECT o.* FROM qry_Styles AS o " + " LEFT JOIN (" + "SELECT [Main Key],MAX([Borrower]) AS [Borrower] FROM [Library Log] WHERE [Date Borrowed] IS NOT NULL AND [Date Returned] IS NULL" + " GROUP BY [Main Key] " + ") As l" + " ON o.[Original Sample Number] = l.[Main Key] " + " WHERE o.[Original Sample Number] LIKE '" + txtOriginalSampleNo.Text.Trim().ToUpper() + "%'" + " AND ISNULL(o.[Product Group],'') LIKE '" + strProductGroup + "'" + " AND ISNULL(o.[Product Type],'') LIKE '" + strProductType + "'" + " AND ISNULL(o.[Gender],'') LIKE '" + strGender + "'" + " AND ISNULL(o.[Batch Number],'') LIKE '" + strBatchNumber + "'" + " AND ISNULL(o.[Designer],'') LIKE '" + strDesigner + "'" + " AND ISNULL(o.[Sample Type],'') LIKE '" + strSource + "'" + " AND ISNULL(o.[Buyer],'') LIKE '" + strBuyer + "'" + " AND ISNULL(l.[Borrower],'') LIKE '" + strBorrower + "'" + " AND ISNULL(o.[Original Brand], '') LIKE '" + strOriginalBrand + "'";
if (strCategory != "") strSQL = strSQL + " AND ISNULL(o.[Category],'') LIKE '" + strCategory + "'";
strSQL = strSQL + " ORDER BY o.[Original Sample Number]"; Session["SQL"] = strSQL; sdsOriginalSamples.SelectCommand = strSQL; grdOriginalSamples.DataBind();
} protected void btnCreateNewRecord_Click(object sender, EventArgs e) { Response.Redirect("~/OriginalSampleForm2.aspx"); } protected void btnReset_Click(object sender, EventArgs e) { txtBatchNo.Text = "*"; txtOriginalSampleNo.Text = ""; cboDesigner.ClearSelection(); cboGender.ClearSelection(); cboOriginalBrand.ClearSelection(); cboProductGroup.ClearSelection(); cboProductType.ClearSelection(); txtOriginalSampleNo.Focus(); }}
Hello Andrea ,
I’ve tested this on my side and it works as expected.
Please feel free to refer to the attached sample and test it on your side.
If you have any questions let me know.
Best Regards,
Maya Kirova
Developer Support Engineer II
Infragistics, Inc.
http://es.infragistics.com/support
I tried string strProductType = cboProductType.CurrentValue.Replace("*", "%"); and it returned this error:
You can add items in the aspx declaration of the control as well as dynamically in code on the server side. Depending on exactly what you’re aiming to achieve it may or may not be redundant.
You can get the current value in the WebDropDown as follows:
<YourWebDropDownID>. CurrentValue
This will return a String.
You can then modify that string additionally if you need to. Assuming that cboProductType is the ID of a WebDropDown control then the code would need to be:
string strProductType = cboProductType.CurrentValue.Replace("*", "%");
Let me know if you have any questions.
A follow up question since I know I'm having a problem on the Apply Button, how to modify this instead?
string strProductType = cboProductType.Text.Replace("*", "%");
Since in my SQL statement it is the value of the % that is being retrieved. Here is the statement: