Hi there,
How do I add an item when I'm already on Form.aspx.cs?
cboOriginalBrand.Items.Add("*"); doesn't work anymore.
Hello Andrea ,
Thank you for posting in our forum.
Do you mean when the page is already loaded in the browser?
If so you can add it on the client side using java script:
http://es.infragistics.com/community/forums/p/78574/398781.aspx#398781
Let me know if you perhaps meant something different.
Best Regards,
Maya Kirova
Developer Support Engineer II
Infragistics, Inc.
http://es.infragistics.com/support
Hello Andrea,
Based on your code alone I cannot determine what control the cboProductGroup and cboBuyer represent and how they’re related to the WebDropDown. Could you elaborate on that?
Also I’m not sure what exactly what you’re trying to achieve with the WebDropDown.
When you select an item from the WebDropDown it’s text will be set in the input element of the drop down. Nothing else is expected to happen by default.
Could you explain in more details what you’re aiming to achieve?
Hi Maya,
I'll take cboProductGroup as an example. That Drop Down has items like 3/4 Henly, etc. When I click on 3/4 Henly and click on "APPLY", on the Grid should appear Products which are in the 3/4 Henly Product Group category. Instead, it doesn't show the products.
I did not place DataSource on the Drop Downs already since I already programmed them on Form.aspx.cs and since the items on the Drop Downs are already showed because of calling them on Form.aspx.cs
Could you describe the exact scenario which you’re trying to implement?
Based on your explanation it seems that cboProductGroup is a WebDropDown control, is that correct?
And when a new item is selected you want to change the data source of a WebDataGrid control on your page.
Let me know if this is what you’re aiming to achieve.
Hi there Maya,
Yes, that is exactly what I meant. When the item on cboProductGroup is selected, it doesn't return the exact result I want for the Grid View to display. I maintained the Grid View using asp.
Ok. In order to get the current text of the editor you need to get the CurrentValue property.
Asuming that cboProductGroup is a WebDropDown then to get the current selected value the code would be:
string strProductGroup =cboProductGroup. CurrentValue;
Let me know if that solves your issue.
I’m just following up to see if you’ve been able to resolve your issue. If you have any questions or concerns or if you need further assistance please let me know.
Developer Support Engineer
I suggest you debug your code and see which element is null on this line:
string strProductType = cboProductType.CurrentValue.Replace("*", "%");
If cboProductType.CurrentValue returns null, then there’s no value entered for the WebDropDown and the CurrentValue returning null is expected.
In that case you can check if the value is null and it it’s null just set it to an empty string :
string strProductType = "";
if (cboProductType.CurrentValue !=null)
{
strProductType = cboProductType.CurrentValue.Replace("*", "%");
}
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(); }}
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.
I tried string strProductType = cboProductType.CurrentValue.Replace("*", "%"); and it returned this error: