how to enable the RadioButtonList while retriving from database - c#

I am using a RadioButtonList,Active and InActive are list items.
I didt specify any values to the list items and i am using this code for inserting the value to the database, every time its taking the true value only..
staffMaster.IsActive = ui_rblIsActive.Enabled == true ? true : false;
staffMaster is a VO object which i created in the WCF layer..
while retriving from database i ve tried this code specified below, for enabling radio button, but its not showing as enabled.. table has only true values..
ui_rblIsActive.Enabled =Convert.ToBoolean(ui_gridView.SelectedRow.Cells[13].Text);
What mistake i have done here???? what i ve to do, to insert & retrive data properly..?

ui_rblIsActive.Enabled is just telling you whether the control is enabled, not what if anything is selected. You want to use ui_rblIsActive.SelectedValue instead. If you did not privde any value you will get the text of the radio button label.

Can you give more information, with the info you provided, I guess you should use rbl's SelectedItem.(Text|Value) property
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist.aspx

Related

Set value of Asp DropDown List is not Working

I have an asp.net DropDownList that I use to filter a RadGrid. After the filter has been applied I can click on a row to edit the record on a separate page. I have a requirement to provide the ability, if the wrong row was selected, to return to the previous search page and display the same records with the same filter. I have taken care of the return and showing the same filtered records.
I also need to show the same value in the dropdown list that was chosen to create the filter. I am trying to do this using a session variable. The session variable gets created on the search click and I am trying to select the same item from the drop down using this code when the user returns to the search page.
string value = (Session["ComplaintType"] != null) ? Session["ComplaintType"].ToString() : String.Empty;
ddlComplaint.Items.FindByValue(value).Selected = true;
It is not working ant I get this error message: Object reference not set to an instance of an object.
Not sure why I am getting that error the string value is equal to the text value of the item selected from the Drop down??
I was able to solve this problem by setting the dropdownlist selected value in the BindDropDown method where I bind the database to the database. Once it was bound I could select a value from the database as the default value.

How to maintain state of drop down list on post back in asp.net VB

I have got a radio button list and based on selection of the radio button list , the drop-downs will populate. Important thing is here the radiobutton list is set to autopostback=true.
And also when i move to next page by button click, And when i come back. Drop down button not able to maintain state. It is losing values. It is important for me to maintain state until i reach the last page. How can i approach this problem. I have used sessions but was not successful. Could you tell me how to implement sessions.
hi #Newyork167 this will not work as he mentioned above that "based on selection of the radio button list , the drop-downs will populate." so you have to store the "RadioButtonList" Selected value and accordingly fillDropDownlist Values and set selected after returning back to the page.
Ok. As per my understanding you need to save a page state so that when you come back then you get the page in previous state where you left. So to do this you have two ways.
1. Before jumping to next page, store everything in session like "Radiobutton selected value", dropdown selected value and other settings if any.
2. Pass these values "Radiobutton selected value", "dropdown selected value" and other if any as the query string and when you coming back then read the same query string.
In either way when you will come back then you will have the previous data. In the page_load event, just check whether you have that data or not. If yes then populate your controls with previous data else populate your controls for first load.
Here is some link for your reference.
http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString
Passing Session[] and Request[] to Methods in C#
If you want to use sessions, you could check the session variable with all of the values of the list
if(Session["selectedList"] != Null){
var check = Session["selectedList"].ToString();
foreach(ListItem item in yourList.Items){
if(item.Value.Equals(check))
// set it as selected
}
}
For storing, when you click the button
Session["selectedList"] = yourList.SelectedValue;
You could also use the indexes instead of the values. You can also create a session variable for each dropdown/radiobuttonlist and you just make a loop for each.
UPDATE
Thanks to Shekhar for pointing this out. You need to go through all of the lists that you want to store and save them with these loops, not just the dropdowns. Then, you need to restore the radio button values, rebind the dropdowns, and then set the selected item for each.

DataGrid Row checkbox filed Not updated in asp.net

hi i m having one datagrid...that have one check box field...whenever i check the check box that time that row will be inserted in database...but check box value is not set true value...it always return false value...i m using C# asp.net 2003 version..please help me...
If you data bind the grid in Page_Load, maybe you don't check for IsPostBack, so, your grid gets rebound and all previous changes like check are not persisted.
if(! Page.IsPostBack)
{
// Data bind the grid
}
Another possible reason is how you try to retrieve the checbox.
We really need to see some code in order to help you.
Its not immediately clear what your problem is. But if I had to guess, since ASP.NET 1.1. doesn't support two-way data binding, I would start with the code that reads the data from the form and updates your data source.

datagridviewcomboboxcolumn not returned with datagridview

i have created a datagridview that is populated with data from the database. When i am displaying the data in my application I add two datagridviewcomboboxcolumns which contain a list of selectable values. These display correctly in the application. The idea is that a user selects a value then hits a button that will take the value and update the database. The problem is that when the update button is pressed the two added datagridviewcolumns are not returned as part of the datagridview, instead when i try to reference the columns in my c# code only the original columns are available.
Please can someone advise as to how I can retrieve the datagridview with the new columns?
Many thanks,
Stu
Issue solved! I was declaring the ComboboxColumn both globally then locally when i was adding it to the datagridview! by removing the local reference and only using global i was able to retrieve the value at a later stage using
ComboboxColumn.DataGridView.Rows[x].Cells[0].Value.ToString();

Different Value Member, same control

Edit 1
I believe my problem stems from the following. The function that fills the dropdown portion sets the Display Member to the CountyName. Then when I try and set the SelectedText or EditValue, as has been suggested, that function only returns the CountyID which it try's to match to something in the DropDown list DisplayMember. I need it to match it to something in the ValueMember list.
Using the following I got it to work but it is a HACK and I'd greatly appreciate finding a real solution.
lkuResidenceCounty.ItemIndex = Convert.ToInt32(row["ResidencyCountyID"].ToString());
Original Post
I have a lookup box(DevExpress) on a member form that I fill the possible values in from the DB with this code -->
lkuResidenceCounty.Properties.DataSource = ConnectBLL.BLL.Person.CountyList();
lkuResidenceCounty.Properties.PopulateColumns();
lkuResidenceCounty.Properties.DisplayMember = "CountyName";
lkuResidenceCounty.Properties.ValueMember = "CountyID";
lkuResidenceCounty.Properties.Columns[0].Visible = false;
lkuResidenceCounty.Properties.Columns[2].Visible = false;
lkuResidenceCounty.Properties.Columns[3].Visible = false;
This works just fine as the CountyName is displayed as expected.
However, When I try and load an existing member's value for this field using the below, which is part of a function that takes a row from the DataSet -->
lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();
I get a blank box. I have stepped through the code and the correct ID is being returned for the member.
Unfortunately the stored procedure to fill the dropdown options pulls from a Maintenance Table with the columns "CountyName" & "CountyID". So that is correct. Unfortunately, the stored procedure to load a specific person's current county pulls from the Person Table where there is a column called "ResidencyCountyID". It is so named because there is also a "ResponsibilityCountyID" column.
I need a way for them both to coexist, any solutions?
Thanks!
DisplayMember and ValueMember are used to populate the control with the list of selectable values. To set the selected value of a populated LookUpEdit control, set its EditValue property:
lkuResidenceCounty.EditValue = row["ResidencyCountyID"].ToString();
In response to your edit: According to the documentation:
The currently selected row determines values for the editor's edit value and display text. The value for BaseEdit.EditValue is obtained from the RepositoryItemLookUpEditBase.ValueMember field, while the text to display in the edit box is obtained from the RepositoryItemLookUpEditBase.DisplayMember field of the selected row.
When you change BaseEdit.EditValue,
the editor locates and selects the row
whose
RepositoryItemLookUpEditBase.ValueMember
field contains the new value. The text
in the edit box is changed to reflect
the newly selected row.
I don't use these controls but it sounds to me that it shouldn't be working as you described. I think the ToString() is the problem because EditValue accepts an object so it's probably expecting an int for the value. Try:
lkuResidenceCounty.EditValue = (int)row["ResidencyCountyID"];
The ValueMember property tells the list what field to pull from when setting the Value property. Once you've set the ValueMember to "CountyID", then when the list is Databound, it will set all the list items' value properties to their respect objects' CountyID fields.
Hence, you should not do:
lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();
but rather
lkuResidenceCounty.Properties.ValueMember = "CountyID";
was perfectly fine, as long as you've correctly identified the field you're trying to databind. Once the list get's databound you should see the results you're expecting.
However, after looking at your code, it seems that you're mismatching your field. In one place you're using ResidencyCountyID and in another you're using CountyID. That is most likely your source of confusion. Figure out what the actual field name is and make sure you set the ValueMember to that.
UPDATE
After reading your comment, what your looking for is the SelectedValue property. The SelectedValue property tells the list to force the selected value to whatever input you give it.
Essentially you have two things going on here. ValueMember tells the list what to use as the value from your data source, and SelectedValue which tells the list what the currently selected value should be.
Why is it that you need the same LookUpEdit to have two value members? Is it being used standalone or in a grid? If standalone, you could swap out the two repository editors depending on the current row. But, are there more than 2 possible values for the ValueMember? That would also complicate things.
UPDATE
Looking at your edit, I think I understand what's going on a little more. So, you don't wish to change your ValueMember (which refers to a data column), but rather to change the value of the editor? If so, then you should definitely use EditValue (not SelectedText, which I don't believe is meant to be set), and assign it to row["value_field"] like so:
lkuResidenceCounty.EditValue = row["ResidencyCountyID"];
What happens when you do that?

Categories

Resources