How to compare 2 datasets and assign that value to repeater - c#

I have 2 datasets. 1 is assigned to dropdown and the other is assigned to repeater. If we select value from drop down, then values in repeater should be populated according to that value.
Initially I have assigned dataview to dropdown:
DataView dw = DataAccess.GetFirmID().Tables[0].DefaultView;
distinctDataTable = dw.ToTable(true, "FirmID");
ddlFirms.DataSource = distinctDataTable;
ddlFirms.DataValueField = "FirmID";
ddlFirms.DataBind();
In repeater:
LinkRepeater.DataSource = DataAccess.GetFirmID();
LinkRepeater.DataBind();
My question: if i change the "FirmID" value, according to that repeater value shoud be populated. Please help me out!

My understanding of your problem is that you want to change the data in a ASP.NET repeater when a certain value is selected in the dropdown.
You should set the AutoPostBack property of the dropdownlist to "true". Then, when the index is changed by the user, the page will postback with the new selected index. You'll want to make sure that the repeater uses the selected item from the dropdownlist to choose what to propagate.

Related

Populate drop down list with current user value as the selected drop down list option asp

I would like to know the best approach on populating a drop down list with all database values, AND have the current value for a user be the selected index. I have the drop down list being populated with the database values, but I'm not sure on how you select. Thank you
Set the DataSource Property of the Dropdown control to the dataSource. The DataSource can be a List or any other kind of DataSource.
Set the DataTextField property, which represent the text, which is displayed for each item in the dropdown list.
Set the DataValueField property, which represent the Unique Value for each item in the dropdown list.
Call the DataBind method of the DropdownList.
To set the selected item, set the SelectedIndex property of the dropdown to the index which needs to be selected.
Following code snippet shows how it can be done..
private void LoadDropdown()
{
dropdownList.DataSource = YourDataSource;
dropdownList.DataTextField = "DisplayPropertyName";
dropdownList.DataValueField = "ValuePropertyName";
// Bind the data to the control.
dropdownList.DataBind();
// Set the default selected item, if desired.
dropdownList.SelectedIndex = indexOfItemWhichShouldBeSelected;
}

Set caption for dropdown list

I have a dropdownlist on a page for which I want to set a text so that whether or not user makes any selection, it should always be displayed to the user and not the selected value.
For example:
Here Select Language should always be visible to user even if I select any value from the list i.e. Option 1 or Option 2.
I guess it is more of a CSS task which I am not very much comfortable with.
If you are talking about a simple asp:DropDownList, you just need to insert an item in it, with an index value of 0 (to deal with server-side checks).
myDropDownList.Items.Insert(0, "Select");
dropdownlist1.Text="SomeText";
Dropdownlist need to have the data-source.
Here Select Language should always be visible to user even if I select
any value from the list i.e. Option 1 or Option 2.
Solution:
if your dropdownlist isn't autopost back enabled then
Maintain a hidden field where on change event of the dropdownlist place the selected value or selected index or selected text there in the hidden field to remember the selection.
lets says the id of your dropdownlist is sel and hidden field is hdSel, the jquery code for that look likes below
$('#sel').change(function(){
var val = $("#sel option:selected").text();
$('#hdSel').val(val);
$("#sel").prop('selectedIndex', 0);
}
);
example on Jsfiddle for your understanding
If your dropdownlist is autopostback enable then you can assign the selected value or selected text or selected index of the dropdownlist to the hidden field and reselect the first item again
Hope this help

How can I get value of a GridView control in Eval?

I have a GridView ItemTemplate column in which I have two controls .. DropDownList and a LinkButton. I want to show the selectedItem of DropDownon LinkButton. I am easily able to do so through code behind from selected index changed event. But the problem is that I am not able to maintain the state of the linkbutton when I add a new row on a button click. (because it is not bound to any datasource)
Anyways, can I bind LinkButton with the selected Value of the Dropdown? Something like:
Eval(drp1.SelectedItem.ToString())
If DropDownList is databound from another table, you can add the "Text Value" of the DropDownList from database and display its value to LinkButton.
For example:
If I've a table holds countries and DropDownList to display them, and I've another table storing country Id. In your scenario you can add Inner Join to your select query and display country name in LinkButton text.

Display Column information from database into my dropdown

I am trying to display Column information from database into my dropdown. After selecting the item in the dropdown (1) the next dropdown (2) must show the list of items present in selected field..net
If you are using ASP.NET dropdownlist you can set autopostback to true and in the codebehind set the items in the second droplist.

Dynamic gridview based on dropdown

I've got a bit of an chicken and an egg.
I need to bind a gridview to a set of database values. The gridview is dynamic and the columns, cells are created at run time.
As such, I need to re-bind the grid on every postback in the pre-init, init events after very post back.
However, the data used to populate the grid uses a value from a dropdown box on the same page. As such, the value of dropdown is not accessible through viewstate until after the init event (i.e. the selected index is always the first item in the list until after on init).
How can I get access to the value of the drop down in time to rebind the grid before the pageload event?
If the Gridview always has the same number of columns, you could have the dynamic query generate column names as aliases, and then just rebind the Gridview on dropdown change?
you can use and HtmlHidden control for store the value you need. It doesn't depend by the viewstate and it's available into the page init

Categories