Unable to bind the searched text in the repeater in c# - 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();

Related

How do I select an object from a list generated by another method?

When my form is loaded, a query is run to get all employee records from SQL. Dapper compiles everything, and I put the contents in a List. My DataGridView table is bound to that list. I have a click event that retrieves the EmployeeID from the first column. Now, how do I sort through the List for the EmployeeModel with the matching ID without repeating the query? I will use this to bind other listboxes with the properties of that EmployeeModel. My first thought was to make the Form_Load method public and have it return employeeList, but it's an async method, and I don't know how to handle that. Would that be the right approach? Is the answer altogether different?
EDIT: I just noticed the first two lines are copied and pasted from my inventory initialization. They should read:
var employeeList = await InitializeEmployeeList();
EmployeeGridView.DataSource = employeeList;
public async void Dash_Load(object sender, System.EventArgs e)
{
var inventoryList = await InitializeInventoryList();
InventoryGridView.DataSource = inventoryList;
//Initialize Employee List
var employeeList = await InitializeEmployeeList();
EmployeeGridView.AutoGenerateColumns = false;
EmployeeGridView.ColumnCount=9;
EmployeeGridView.AutoSize = true;
EmployeeGridView.DataSource = employeeList;
EmployeeGridView.Columns[0].HeaderText = "Employee ID";
EmployeeGridView.Columns[0].DataPropertyName = "ID";
EmployeeGridView.Columns[1].HeaderText = "First Name";
EmployeeGridView.Columns[1].DataPropertyName = "FirstName";
EmployeeGridView.Columns[2].HeaderText = "Last Name";
EmployeeGridView.Columns[2].DataPropertyName = "LastName";
EmployeeGridView.Columns[3].HeaderText = "Nickname";
EmployeeGridView.Columns[3].DataPropertyName = "Nickname";
EmployeeGridView.Columns[4].HeaderText = "JobTitle";
EmployeeGridView.Columns[4].DataPropertyName = "JobTitle";
EmployeeGridView.Columns[5].HeaderText = "Forklift";
EmployeeGridView.Columns[5].DataPropertyName = "ForkliftCert";
EmployeeGridView.Columns[6].HeaderText = "AWP";
EmployeeGridView.Columns[6].DataPropertyName = "AWPCert";
EmployeeGridView.Columns[7].HeaderText = "Confined Space";
EmployeeGridView.Columns[7].DataPropertyName = "ConfinedSpaceCert";
EmployeeGridView.Columns[8].HeaderText = "NFPA51b";
EmployeeGridView.Columns[8].DataPropertyName = "NFPA51bCert";
}
{
DataGridViewCell selectedEmployeeCell = EmployeeGridView.CurrentCell;
int selectedEmployeeRow = selectedEmployeeCell.RowIndex;
string selectedEmployeeID = EmployeeGridView.Rows[selectedEmployeeRow].Cells[0].Value.ToString();
}
put a global
public static InvertoryList lst;
after getting data from your method
fill it with your data
if(lst==null)lst=new InvertoryList();
lst=your inventoryList;
then you can reach lst from everywhere in your form.

How to Get Populate Comboboxes Values From Gridview in WinForm?

I want to get grid view data in the StudentRegistrationForm. I have tried many times, but I am unable do this, and I don't understand. Can you tell me how I can get GridView values in my StudentRegistrationForm?
If I comment combo boxes code, then other values are put in StudentRegistrationForm, but I want to show all data in StudentRegistrationForm.
St_Registration obj = new St_Registration();
int St_Id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
obj.txt_name.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
obj.txt_fname.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
obj.txt_sur_name.Text =dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
obj.txt_email.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
obj.dob_date.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
obj.date_of_registration.Text=dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
obj.txt_address.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
obj.rbtn_male.Checked = true;
obj.rbtn_female.Checked = false;
if (dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString() == "Female")
{
obj.rbtn_male.Checked = false;
obj.rbtn_female.Checked = true;
}
obj.txt_contact.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString();
obj.cmb_country.Text=dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString();
obj.cmb_province.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString();
obj.cmb_city.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString();
obj.txt_pin.Text=dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString();
obj.ShowDialog();

How to implement autocomplete combobox that can search substring for my windows form app?

Here In image as I press i it is showing all books from i. but i want to search
from sub string like i want all books that contain india anywhere in title
In my program data is fetching from data base.It is already serching from the beginning but now i want to search any substring from it.Code is given below please help me fit it.
sRetVal = GlobalFuncs.GetPersonListWithCondition(ref dtPerson, Convert.ToString(cboPersonCategory.SelectedValue));
if (sRetVal == GlobalFuncs.SUCCESS)
{
var source = new AutoCompleteStringCollection();
source.AddRange(dtPerson.AsEnumerable().Select<System.Data.DataRow, String>(x => x.Field<String>("PersonName")).ToArray());
cboPerson.AutoCompleteCustomSource = source;
cboPerson.DataSource = dtPerson;
cboPerson.AutoCompleteMode = AutoCompleteMode.Suggest;
cboPerson.DisplayMember = "PersonName";
cboPerson.ValueMember = "PersonID";
}
else
{
MessageBox.Show(sRetVal);
return;
}
sRetVal = GlobalFuncs.GetPersonListWithCondition(ref dtPerson, Convert.ToString(cboPersonCategory.SelectedValue));
if (sRetVal == GlobalFuncs.SUCCESS)
{
var source = new AutoCompleteStringCollection();
source.AddRange(dtPerson.AsEnumerable().Select<System.Data.DataRow, String>(x => x.Field<String>("PersonName")).ToArray());
cboPerson.AutoCompleteCustomSource = source;
cboPerson.DataSource = dtPerson;
cboPerson.AutoCompleteMode = AutoCompleteMode.Suggest;
cboPerson.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
cboPerson.DisplayMember = "PersonName";
cboPerson.ValueMember = "PersonID";
}
else
{
MessageBox.Show(sRetVal);
return;
}
Keep coding!

Dropdown value not changing

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

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