Dropdown value not changing - c#

I'm trying to bind my printers name in the dropdown and managed show all the printer name in my dropdown. When I try to get the value of selected item, it show the first value for all the printer. Below is the code
Code to bind the printer name:
PrintModuleAX printModuleAX = new PrintModuleAX();
var result = printModuleAX.GetAllPrinterNames();
JObject o = JObject.Parse(result);
JArray sizes = (JArray)o["PrinterNames"];
var dt = new DataTable();
dt.Columns.Add("PrinterValue");
dt.Columns.Add("PrinterName");
for (int i = 0; i < sizes.Count; i++)
{
dt.Rows.Add((string)sizes[i], (string)sizes[i]);
}
ddlPrinterName.DataSource = dt;
ddlPrinterName.DataTextField = dt.Columns["PrinterName"].ToString();
ddlPrinterName.DataValueField = dt.Columns["PrinterValue"].ToString();
ddlPrinterName.DataBind();
code to get the selected value:
var printername = ddlPrinterName.Text.ToString();
var printername1 = ddlPrinterName.SelectedValue.ToString();
var printername2 = ddlPrinterName.SelectedItem.ToString();
printername, printername1, printername2 show the same value even though I chose a different printer.

Check that the databinding is not happening every page load. (use if (!page.ispostback))

Try with below code
ddlPrinterName.DataSource = dt;
//just specify the column name
ddlPrinterName.DataTextField = "PrinterName";
ddlPrinterName.DataValueField = "PrinterValue";
ddlPrinterName.DataBind();
var printername1 = ddlPrinterName.SelectedItem.Text; //gives text
var printername2 = ddlPrinterName.SelectedItem.Value; //gives value

Related

C# Winform Getting Value from CheckListBox

I have a checkedListBox on a winform.
I fill the check box with some code see below.
All works well.
Now I need to get the value of the checked items. I am having some issues.
When I do the foreach(var item in clbtest.CheckedItems)
I get this when doing a Immediate window... ? item
{ Text = "Depos", Value = "Q:\\Scanning Department\\_DT SEARCH INDEXES\\Depos" }
Text: "Depos"
Value: "Q:\\Scanning Department\\_DT SEARCH INDEXES\\Depos"
I don't know how to get at the Value field. I have tried several ways but nothing seems to work.
private void FillIndexes()
{
string stext = cblIndexToSearch.Text;
cblIndexToSearch.Items.Clear();
cblIndexToSearch.Text = "";
cblIndexToSearch.DisplayMember = "Text";
cblIndexToSearch.ValueMember = "Value";
foreach (var item in indexlist)
{
cblIndexToSearch.Items.Insert(0,
new { Text = item.indexName, Value = #item.indexPath });
}
}
Hope this helps. Just create a checklistbox named "checkedListBox1" and the code should work. I detailed a little on what it does.
checkedListBox1.Items.Clear();
checkedListBox1.Text = "";
checkedListBox1.DisplayMember = "Text";
checkedListBox1.ValueMember = "Value";
checkedListBox1.Items.Insert(0,
new { Text = "Rawr", Value = "Whatever 2011"});
string temp = checkedListBox1.Items[0].ToString(); //gets the string of the item. (switch 0 to the index you want)
string string_Value = temp.Split(new string[] { "Value = " }, StringSplitOptions.None)[1]; //splits the string by the value part and returns the string value.
string_Value = string_Value.Substring(0, string_Value.Length - 2); ; //removes the last 2 characters since they are not part of the value.
//you now have the value in string form.

C# ClosedXML assign values from cells in a specific row to string

I'm using ClosedXML elsewhere in my script where I'm iterating through every row like this and it works.
var workbook = new XLWorkbook(ObjectRepPath);
var rows = workbook.Worksheet(1).RangeUsed().RowsUsed().Skip(1);
foreach (var row in rows)
{
objPage = row.Cell(1).GetString();
objElement = row.Cell(2).GetString();
if (objPage == page && objElement == element)
{
locType = row.Cell(3).GetString();
locParm = row.Cell(4).GetString();
}
}
After that I need to pull the data from the cells in a randomly selected row. Here's what I've got so far, which is not working...
var workbook = new XLWorkbook(extFile);
var ws = workbook.Worksheets.Add("Cell Values");
var rnd = new Random();
int rowNum = rnd.Next(2, workbook.Worksheet(1).RangeUsed().RowsUsed().Count());
var dataRow = ws.Row(rowNum);
string dangit = dataRow.Cell(1).GetString();
System.Diagnostics.Debug.WriteLine("Why is this dang thing not working... " + dangit);
Output: Why is this damn thing not working...
It just comes back empty. No error. Does anyone see something I don't?
Alright, I found the solution.
I changed the line ...
var ws = workbook.Worksheets.Add("Cell Values");
to ....
var ws = workbook.Worksheet(1);
and now this works ....
Storage.StreetAddress = ws.Cell(xlRow, 1).GetString();

Unable to bind the searched text in the repeater in c#

I am trying to search the text(keywords) among the list which are bind to the repeater controller.I have a pagination implemented using the Data List. If I search the text, I will get the data source count as one, but if I check the result view "Enumeration yielded no results" error will come and the repeater will have no value
Here is my code
string authorname = AuthorNames();
string ProdTitle = ProductTitle();
string refno = ProductRefno();
List<Product> ProductList = GetProductDetails(categoryName, refno, ProdTitle, authorname);
pageDataSource.DataSource = ProductList;
pageDataSource.AllowPaging = true;
pageDataSource.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue);
pageDataSource.CurrentPageIndex = CurrentPage;
lnkbtnNext.Enabled = !pageDataSource.IsLastPage;
lnkbtnPrevious.Enabled = !pageDataSource.IsFirstPage;
ViewState["totpage"] = pageDataSource.PageCount;
repproductlist.DataSource = pageDataSource;
repproductlist.DataBind();
DoPaging();
// Int32 value = Convert.ToInt32(ConfigurationManager.AppSettings["PaginationDisplayAt"]);
if (ProductList.Count > PaginationDisplayAt)
{
this.paginationDiv.Visible = true;
}
else
{
this.paginationDiv.Visible = false;
}
any help will be usefull
you probably need to create a new list from the search result before you bind it.
repproductlist.DataSource = pageDataSource.FindAll(x => x.Text.Contains(searchString)).ToList();

How to add brand to existing eBay item?

In my application I would like add Brand and MPN to existing eBay item via API on C#, so, I run code:
string eCommerceID = (dr["eCommerceID"] ?? "").ToString().Trim();
string upc = (dr["UPC"] ?? "").ToString().Trim();
string manufacturerName = (dr["ManufacturerName"] ?? "").ToString().Trim();
string brandMPN = (dr["BrandMPN"] ?? "").ToString().Trim();
ReviseItemRequestType reviseItemRequestType = new ReviseItemRequestType();
reviseItemRequestType.Version = version;
reviseItemRequestType.Item = new ItemType();
reviseItemRequestType.Item.ItemID = eCommerceID;
reviseItemRequestType.Item.ProductListingDetails = new ProductListingDetailsType();
reviseItemRequestType.Item.ProductListingDetails.UPC = upc;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN = new BrandMPNType();
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.Brand = manufacturerName;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.MPN = brandMPN;
ReviseItemResponseType reviseItemResponseType = ebayService.ReviseItem(reviseItemRequestType);
but when I execute this code, eBay returns error:
"The item specific Brand is missing. Add Brand to this listing, enter a valid value, and then try again."
What I'm doing wrong?
Appreciate any help. Thanks.
Error:
As the error messages says:
The item specific Brand is missing
Don't use the Item.ProductListingDetails.BrandMPN in your request. Instead you will need to create two Item Specifics called Band and MPN.
<ItemSpecifics>
<NameValueList>
<Name>Brand</Name>
<Value>[BRAND VALUE]</Value>
</NameValueList>
<NameValueList>
<Name>MPN</Name>
<Value>[MPN VALUE]</Value>
</NameValueList>
</ItemSpecifics>
Here is copy paste code snippet of the C# solution.
ItemType itemType = new ItemType(); // = class eBay.Service.Core.Soap.ItemType
Int32 condCodeAsInt = 1000; // upto you to derrive this from your use case.
String myBrandValue = "Some BRAND";
String myMpnValue = "some MPN";
String myUpcValue = "Does not apply";
....
//if condition is "New" or "New with Details" then we need to set extra REQUIRED fields
if (condCodeAsInt == 1000 || condCodeAsInt == 1500)
{
//if it is "new" then remove inputted desc text completely REQUIRED
if (condCodeAsInt == 1000)
{
itemType.ConditionDescription = "";
}
// set UPC value HERE, not in ItemSpecifics.
ProductListingDetailsType pldt = new ProductListingDetailsType();
pldt.UPC = myUpcValue;
itemType.ProductListingDetails = pldt;
//init Item specifics ( and set BRAND and MPN )
itemType.ItemSpecifics = new NameValueListTypeCollection();
//brand
NameValueListType nvBrand = new NameValueListType();
nvBrand.Name = "Brand";
StringCollection brandStringCol = new StringCollection();
brandStringCol.Add(myBrandValue);
nvBrand.Value = brandStringCol;
itemType.ItemSpecifics.Add(nvBrand);
//MPN
NameValueListType nvMpn = new NameValueListType();
nvMpn.Name = "MPN";
StringCollection mpnStringCol = new StringCollection();
mpnStringCol.Add(myMpnValue);
nvMpn.Value = mpnStringCol;
itemType.ItemSpecifics.Add(nvMpn);
}

How can i set up all the data's in the textbox

first of all there is a searchbox form and a view form. after passing the value of the id in the searchbox, it should return all the values that matches with the id of that person after the textchange method occured. but it doesn't display a single value on the textboxes. here is my code
public void first_tab_search(string key)
{
key = txtSearch.Text;
var first = from a in dbcon.personal_informations where a.last_name == key select a;
foreach (var setThem in first)
{
txtsurname.Text = setThem.last_name;
txtfirstname.Text = setThem.first_name;
txtmiddlename.Text = setThem.middle_name;
txtID.Text = setThem.userid;
txtweight.Text = setThem.weight;
txttin.Text = setThem.tin;
txtsss.Text = setThem.sss;
txtaeno.Text = setThem.agency_employee_no;
txtbloodtype.Text = setThem.blood_type;
txtcitizenship.Text = setThem.citizenship;
txtcivilstatus.Text = setThem.civil_status;
txtcpno.Text = setThem.cell_no;
txtdob.Text = setThem.datetime_of_birth.ToString();
txtemail.Text = setThem.email_address;
txtgender.Text = setThem.sex;
txtgsis.Text = setThem.gsis_id;
txtheight.Text = setThem.height;
txtnameext.Text = setThem.name_ext;
txtpagibig.Text = setThem.pagibig_id;
txtpermaaddr.Text = setThem.permanent_address;
txtpermatelno.Text = setThem.permanent_telno;
txtpermazip.Text = setThem.permanent_zipcode;
txtphilhealth.Text = setThem.philhealth;
txtpob.Text = setThem.place_of_birth;
txtresidentialaddr.Text = setThem.residential_address;
txtresitelno.Text = setThem.residential_telno;
txtresizip.Text = setThem.residential_zipcode;
txtweight.Text = setThem.weight;
}
}
You have a whole host of problems going on here.
You pass a key into the method, and then immediately overwrite it with the contents of your search box.
Your search could return more than one result, and therefore your code is looping through each result and overwriting the output values with the last returned row. Use += rather than + in your loop, i.e.
txtsurname.Text += setThem.last_name;
Your code is currently case sensitive, this may be the desired approach but might not be.

Categories