This is a migrated thread and some comments may be shown as answers.

[Solved] Bind the ComboBox according which checkbox checked.

5 Answers 197 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
abhay
Top achievements
Rank 1
abhay asked on 21 Apr 2009, 12:26 PM
Hi,

I have two checkboxes and query will build dyanamically which checkbox is checked.

Here is the code


 

private DataTable GetData(string text)

 

{

objUser = (

LoggedUser)Session["USER"];

 

 

string appendSql = string.Empty;

 

objUser = (

LoggedUser)Session["USER"];

 

 

string appendText = string.Empty;

 

 

string appText = string.Empty;

 

 

string fillMedication = string.Empty;

 

 

int catType = 0;

 

 

if (RbtnOral.Checked == true)

 

{

catType =

TypeID.ORAL_TYPE;

 

}

 

else

 

{

catType =

TypeID.TOPICAL_TYPE;

 

}

 

if (text != "")

 

{

appendText =

" AND LD.DRUG_NAME LIKE '" + text + '%' + "' ";

 

appText =

"AND LPM.DRUG_NAME LIKE '" + text + '%' + "' ";

 

}

 

if (chkStandard.Checked == true)

 

{

fillMedication =

"SELECT TOP 10 LD.DRUG_NAME AS MEDICATION, PK_DRUG_ID AS PKMEDICATION FROM L_DRUGNAME LD " +

 

 

"WHERE " +

 

 

" LD.DRUG_NAME IS NOT NULL " + appendText + " ";

 

}

 

else

 

{

fillMedication =

"SELECT LD.DRUG_NAME as MEDICATION,PK_ID as " +

 

 

"PKMEDICATION,case LPM.STRENGTH when ' ' then ' ' " +

 

 

"else isnull((select strength from l_strength where " +

 

 

"CONVERT(VARCHAR,pk_stren_id)=LPM.STRENGTH),' ') " +

 

 

"end as STRENGTH,PK_ID as PKSTRENGTH,case LPM.DIRECTIONS when ' ' then ' ' " +

 

 

"else isnull((select DIRECTIONS from L_DIRECTIONS where " +

 

 

"Convert(varchar,PK_DIR_ID)=LPM.DIRECTIONS),' ') " +

 

 

"end as DIRECTIONS,PK_ID as " +

 

 

"PKDIRECTIONS from L_PREFERED_MEDICATION LPM,L_DRUGNAME LD where " +

 

 

"CONVERT(VARCHAR,pk_drug_id)=LPM.DRUG_NAME " + appendText + " " +

 

 

"and LPM.DRUG_NAME IS NOT NULL " +

 

 

" AND LPM.FK_PRACTIONER_ID = " + objUser.PractitionerID + " AND LPM.STATUS = 1 AND IS_CUSTOM = 'FALSE' AND LPM.Category =" + catType + " " +

 

 

"UNION " +

 

 

"SELECT DRUG_NAME AS MEDICATION, LPM.PK_ID,LPM.STRENGTH AS STRENGTHSTR, " +

 

 

"LPM.PK_ID AS PKSTRENGTH,LPM.DIRECTIONS AS 'DIRECTIONSSTR',LPM.PK_ID AS 'PKDIRECTIONS' " +

 

 

"FROM L_PREFERED_MEDICATION LPM WHERE LPM.FK_PRACTIONER_ID = " + objUser.PractitionerID + " " +

 

 

"AND LPM.STATUS = 1 AND IS_CUSTOM = 'TRUE' " + appText + " and DRUG_NAME IS NOT NULL AND LPM.Category =" + catType +" ";

 

 

}

 

DataTable dtData = SqlHelper.ExecuteDataset(new Connection().GetCon, CommandType.Text, fillMedication).Tables[0];

 

 

return dtData;

 

}



protected

 

void RadComboBoxMedication_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)

 

{

 

DataTable data = GetData(e.Text);

 

RadComboBoxMedication.Items.Clear();

 

string text = e.Text;

 

 

DataRow[] rows = data.Select();

 

 

int itemsPerRequest = 10;

 

 

int itemOffset = e.NumberOfItems;

 

 

int endOffset = itemOffset + itemsPerRequest;

 

 

if (endOffset > rows.Length)

 

{

endOffset = rows.Length;

}

 

for (int i = itemOffset; i < endOffset; i++)

 

{

RadComboBoxMedication.Items.Add(

new RadComboBoxItem(data.Rows[i]["MEDICATION"].ToString(), data.Rows[i]["PKMEDICATION"].ToString()));

 

}

 

// e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset, rows.Length);

 

e.Message = GetStatusMessage(endOffset, data.Rows.Count);

}


even after i uncheck chkStandard checkbox or rbtnOral radioButton but it shows it is checked.


Plz help me.

5 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 21 Apr 2009, 01:05 PM
Hello abhay,

In the ItemsRequested event handler the actual states of the Page controls are not available. That is why the CheckBox/RadioButton Checked property returns always the initial value.

To workaround this limitation you need to send the checked states of both controls from the client to the ItemsRequested event handler via the Context object in the OnClientItemsRequesting event handler.

Please see this help topic for an example of the approach.

Kind regards,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
abhay
Top achievements
Rank 1
answered on 21 Apr 2009, 02:11 PM
Hi

i have done that and it is working ,but one problem is there when i am using this combobox like dropdown (click on rightside on combobox to show the all data)first it invoke the 

ItemsRequested method but for second time it isnot calling that method so when i will check another checkbox the data for first checkbox will be there and it will show this data which is wrong.

Plz help me .

0
Simon
Telerik team
answered on 21 Apr 2009, 03:58 PM
Hi abhay,

RadComboBox loads its Items automatically on the first drop down opening.

In your case, you could either handle the client-side click event of the CheckBox and call requestItems on the ComboBox to load its Items (whenever the CheckBox is checked/unchecked) or handle the OnClientDropDownOpening event in the way shown below:

function onDropDownOpening(sender, eventArgs) { 
    if ( ! sender.dropDownOpenedOnce) { 
        sender.dropDownOpenedOnce true
    } 
    else { 
        sender.requestItems([text], false); 
    } 

Best wishes,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
abhay
Top achievements
Rank 1
answered on 22 Apr 2009, 05:51 AM
hi,

I HAVE USED THIS CODE  BUT IT FAILED FIRST TIME ,THEN IT SUCESSES ,WHEN I CHWCK ANOTHER CHECKBOX AND CLICK ON COMBOBOX IT SHOWS NO MATCHES ,THEN I CLOSE IT AND OPEN IT SHOWS THE DATA AND  IF DEBUG THE CODE IT ALSO SUCCESS FOR FIRST TIME THE ABOVE PROBLEM DOESN'T OCCUR.

 

function onDropDownOpening(sender, eventArgs)

 

{

 

if ( ! sender.dropDownOpenedOnce) {

 

sender.dropDownOpenedOnce =

true;

 

}

 

else {

 

 

sender.requestItems(sender.get_text(),

false);

 

}

}


PLZ HELP ME.
0
Simon
Telerik team
answered on 24 Apr 2009, 04:44 PM
Hello abhay,

Could you please paste your RadComboBox definition and the ItemsReqesting/ed event handler(s) code as well?

Greetings,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ComboBox
Asked by
abhay
Top achievements
Rank 1
Answers by
Simon
Telerik team
abhay
Top achievements
Rank 1
Share this question
or