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

combobox with checkbox binding error when bound to radgrid

1 Answer 53 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sateesh kumar
Top achievements
Rank 1
Sateesh kumar asked on 23 Mar 2010, 11:28 AM
dear sir,
i am using radgrid to fill the data.when a record is selected from grid ,i am filling controls that i need to edit.
simle combo box is working fine,where as combo box with check box repeating the one item that bind at runtime.
i am filling controls using client side code.

here is the code i wrote for databound:

protected

 

void RadGrid1_DataBound(object sender, EventArgs e)

 

{

 

 

GridDataItem selectedItem = RadGrid1.Items[0];

 

txtFeeTypeCode.Text = selectedItem[

"Code"].Text;

 

txtFeeTypeName.Text = selectedItem[

"Fee Type"].Text;

 

 

for (int i = 0; i < ddlFrequency.Items.Count; i++)

 

{

 

if (ddlFrequency.Items[i].Text == selectedItem["Frequency"].Text)

 

{

ddlFrequency.SelectedValue = i.ToString();

}

}

 

string defaultList = selectedItem["Months"].Text;

 

 

ArrayList al = new ArrayList();

 

 

object[] objs = null;

 

 

for (int i = 0; i < defaultList.Length; i++)

 

{

objs = defaultList.Split(

' ');

 

}

 

foreach (string st in objs)

 

{

 

if (st != "")

 

{

al.Add(st);

}

}

 

foreach (RadComboBoxItem item in RadComboBox1.Items)

 

{

 

CheckBox checkBox = (CheckBox)item.FindControl("CheckBox");

 

checkBox.Checked =

false;

 

}

 

foreach (RadComboBoxItem item in RadComboBox1.Items)

 

{

 

for (int x = 0; x < al.Count; x++)

 

{

 

if (al[x].ToString() == item.Text)

 

{

 

CheckBox chk1 = (CheckBox)item.FindControl("CheckBox");

 

chk1.Checked =

true;

 

RadComboBox1.SelectedItem.Text = chk1.Text;

}

}

}

txtInstallMents.Text = selectedItem[

"Installments"].Text;

 

 

if (selectedItem["Refundable"].Text != "")

 

{

 

if (selectedItem["Refundable"].Text == "True")

 

{

radcboIsref.SelectedIndex = 0;

}

 

else

 

{

radcboIsref.SelectedIndex = 1;

}

}

 

if (selectedItem["Description"].Text.Trim() != "")

 

{

txtDesc.Text = selectedItem[

"Description"].Text.Trim();

 

}

 

else

 

{

txtDesc.Text =

string.Empty;

 

}

}

this is client side code to fill controls when a row selected from radgrid :

<

 

telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

 

 

<script type="text/javascript">

 

 

var id, currentFeeType, currentRowIndex = null;

 

 

 

 

function RowSelected(sender, args) {

 

 

var typecode;

 

typecode = args.getDataKeyValue(

"Code");

 

document.getElementById(

'<%= txtFeeTypeCode.ClientID %>').value = typecode;

 

document.getElementById(

'<%= txtFeeTypeName.ClientID %>').value=args.getDataKeyValue("Fee Type");

 

document.getElementById(

'<%= ddlFrequency.ClientID %>').value = args.getDataKeyValue("FrequencyId");

 

 

var Months = args.getDataKeyValue("Months");

 

clearMonthsCombo();

 

fillMonthsCombo(Months);

 

document.getElementById(

'<%= txtInstallMents.ClientID %>').value = args.getDataKeyValue("Installments");

 

 

var ifv = args.getDataKeyValue("Refundable");

 

 

var DropdownList = document.getElementById('<%= radcboIsref.ClientID %>');

 

 

 

if (args.getDataKeyValue("Refundable") == "True") {

 

DropdownList.value = 1;

}

 

else {

 

DropdownList.value = 0;

}

document.getElementById(

'<%= txtDesc.ClientID %>').value = args.getDataKeyValue("Description");

 

 

var tabStrip = $find("<%=RadTabStrip1.ClientID%>");

 

 

var tabEditFeeType = tabStrip.findTabByText("Edit Fee Type");

 

tabEditFeeType.select();

}

 

function clearMonthsCombo() {

 

 

var combo = $find("<%= RadComboBox1.ClientID %>");

 

 

var comboitems = combo.get_items();

 

 

var comboitemsCount = comboitems.get_count();

 

 

 

 

for (i = 0; i < comboitemsCount; i++) {

 

 

var comboitem = comboitems.getItem(i);

 

 

var checkbox = getItemCheckBox(comboitem);

 

checkbox.checked =

false;

 

}

 

combo.clearSelection();

 

}

 

function fillMonthsCombo(Months) {

 

 

var combo = $find("<%= RadComboBox1.ClientID %>");

 

 

var arr = Months.split(", ");

 

 

var itemsCount = arr.length;

 

 

for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++) {

 

 

var Month = arr[itemIndex];

 

 

var comboitems = combo.get_items();

 

 

var comboitemsCount = comboitems.get_count();

 

 

 

for (i = 0; i < comboitemsCount; i++) {

 

 

var comboitem = comboitems.getItem(i);

 

 

var checkbox = getItemCheckBox(comboitem);

 

 

var comboMonth = comboitems.getItem(i).get_text();

 

 

var monthValue = combo.get_value();

 

 

 

if (Month == comboMonth) {

 

checkbox.checked =

true;

 

}

 

}

}

collectSelectedItems();

 

}

 

function getDataItemKeyValue(radGrid, item) {

 

 

return parseInt(radGrid.get_masterTableView().getCellByColumnUniqueName(item, "Id").innerHTML);

 

}

 

 

 

function tabSelected(sender, args)

 

{

 

 

switch(args.get_tab().get_index())

 

{

 

case 1:

 

{

 

var grid = $find("<%= RadGrid1.ClientID %>")

 

grid.get_masterTableView().clearSelectedItems();

 

document.getElementById(

'<%=SaveChanges.ClientID%>').value = "Save";

 

document.getElementById(

'<%= Delete.ClientID%>').style.display = "none";

 

document.getElementById(

'<%= txtFeeTypeCode.ClientID %>').value = "Auto";

 

document.getElementById(

'<%= txtFeeTypeCode.ClientID %>').disabled = true;

 

document.getElementById(

'<%= txtFeeTypeName.ClientID %>').value = "";

 

document.getElementById(

'<%= ddlFrequency.ClientID %>').value = 0;

 

document.getElementById(

'<%= txtInstallMents.ClientID %>').value = "";

 

document.getElementById(

'<%= radcboIsref.ClientID %>').value = 0;

 

document.getElementById(

'<%= txtDesc.ClientID %>').value = "";

 

clearMonthsCombo();

 

break;

 

}

 

default:

 

{

 

document.getElementById(

'<%= Delete.ClientID%>').style.display = "";

 

document.getElementById(

'<%=SaveChanges.ClientID%>').value = "Update";

 

document.getElementById(

'<%= Delete.ClientID%>').value = "Delete";

 

getGridRows();

 

break;

 

}

}

}

 

function getGridRows() {

 

 

var grid = $find("<%= RadGrid1.ClientID %>")

 

grid.get_masterTableView().clearSelectedItems();

 

var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();

 

 

var dataItem = masterTable.get_dataItems();

 

dataItem[0].set_selected(

true);

 

 

}

 

function ChangeButtons() {

 

 

 

document.getElementById(

'<%=SaveChanges.ClientID%>').value = "Save";

 

document.getElementById(

'<%= Delete.ClientID%>').style.display = "none";

 

document.getElementById(

'<%= txtFeeTypeCode.ClientID %>').value = "Auto";

 

document.getElementById(

'<%= txtFeeTypeCode.ClientID %>').disabled = true;

 

document.getElementById(

'<%= radcboIsref.ClientID %>').value = 0;

 

 

}

 

function ToggleConcession(cntrl, txt1,txt2) {

 

 

if (cntrl.checked) {

 

txt1.disabled =

false;

 

txt2.disabled =

false;

 

}

 

else {

 

 

if (txt1.value != 0 || txt2.value != 0) {

 

 

var answer = confirm("Disable will remove any values from Min.Concession and Max.Concession.\nAre you sure?")

 

 

if (answer) {

 

txt1.disabled =

true;

 

txt2.disabled =

true;

 

txt1.value = 0;

txt2.value = 0;

}

 

else {

 

cntrl.checked =

true;

 

 

return;

 

}

}

 

else {

 

txt1.disabled =

true;

 

txt2.disabled =

true;

 

}

 

}

}

 

function PaymentRowSelected(sender, args) {

 

 

var typecode;

 

typecode = args.getDataKeyValue(

"Code");

 

document.getElementById(

'<%= txtPaymentCode.ClientID %>').value = typecode;

 

document.getElementById(

'<%= txtPaymentName.ClientID %>').value = args.getDataKeyValue("Name");

 

 

 

var ifv = args.getDataKeyValue("Status");

 

 

var DropdownList = document.getElementById('<%= ddlPaymentStatus.ClientID %>');

 

 

if (args.getDataKeyValue("Status") == "True") {

 

DropdownList.value = 1;

}

 

else {

 

DropdownList.value = 0;

}

 

 

var tabStrip = $find("<%=RadTabStrip2.ClientID%>");

 

 

var tabEditFeeType = tabStrip.findTabByText("Edit Payment Mode");

 

tabEditFeeType.select();

}

 

 

function PaymenttabSelected(sender, args) {

 

 

switch (args.get_tab().get_index()) {

 

 

case 1:

 

{

 

var grid = $find("<%= RadGrid3.ClientID %>")

 

grid.get_masterTableView().clearSelectedItems();

document.getElementById(

'<%=btnPaymentSaveChanges.ClientID%>').value = "Save";

 

document.getElementById(

'<%= btnPaymentDelete.ClientID%>').style.display = "none";

 

document.getElementById(

'<%= txtPaymentCode.ClientID %>').value = "Auto";

 

document.getElementById(

'<%= txtPaymentCode.ClientID %>').disabled = true;

 

document.getElementById(

'<%= txtPaymentName.ClientID %>').value = "";

 

document.getElementById(

'<%= ddlPaymentStatus.ClientID %>').value = 0;

 

 

 

break;

 

}

 

default:

 

{

document.getElementById(

'<%= btnPaymentDelete.ClientID%>').style.display = "";

 

document.getElementById(

'<%=btnPaymentSaveChanges.ClientID%>').value = "Update";

 

document.getElementById(

'<%= btnPaymentDelete.ClientID%>').value = "Delete";

 

getGrid3Rows();

 

break;

 

}

}

}

 

function getGrid3Rows() {

 

 

var grid = $find("<%= RadGrid3.ClientID %>")

 

grid.get_masterTableView().clearSelectedItems();

 

var masterTable = $find("<%=RadGrid3.ClientID%>").get_masterTableView();

 

 

var dataItem = masterTable.get_dataItems();

 

 

if (dataItem.length != 0) {

 

dataItem[0].set_selected(

true);

 

}

}

 

function ChangeButtonsOfPaymentMode() {

 

 

document.getElementById(

'<%=btnPaymentSaveChanges.ClientID%>').value = "Save";

 

document.getElementById(

'<%= btnPaymentDelete.ClientID%>').style.display = "none";

 

document.getElementById(

'<%= txtPaymentCode.ClientID %>').value = "Auto";

 

document.getElementById(

'<%= txtPaymentCode.ClientID %>').disabled = true;

 

document.getElementById(

'<%= ddlPaymentStatus.ClientID %>').value = 0;

 

}

 

 

</script>

 

 

<script type="text/javascript">

 

 

var supressDropDownClosing = false;

 

 

function OnClientDropDownClosing(sender, eventArgs) {

 

eventArgs.set_cancel(supressDropDownClosing);

}

 

function OnClientSelectedIndexChanging(sender, eventArgs) {

 

eventArgs.set_cancel(supressDropDownClosing);

}

 

function OnClientDropDownOpening(sender, eventArgs) {

 

supressDropDownClosing =

true;

 

}

 

function OnClientBlur(sender) {

 

supressDropDownClosing =

false;

 

sender.toggleDropDown();

}

 

function checkboxClick() {

 

collectSelectedItems();

}

 

function getItemCheckBox(item) {

 

 

//Get the 'div' representing the current RadComboBox Item.

 

 

var itemDiv = item.get_element();

 

 

//Get the collection of all 'input' elements in the 'div' (which are contained in the Item).

 

 

var inputs = itemDiv.getElementsByTagName("input");

 

 

for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++) {

 

 

var input = inputs[inputIndex];

 

 

//Check the type of the current 'input' element.

 

 

if (input.type == "checkbox") {

 

 

return input;

 

}

}

 

return null;

 

}

 

function collectSelectedItems() {

 

 

 

var combo = $find("<%= RadComboBox1.ClientID %>");

 

 

//alert(combo);

 

 

var items = combo.get_items();

 

 

var selectedItemsTexts = "";

 

 

var selectedItemsValues = "";

 

 

var itemsCount = items.get_count();

 

 

for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++) {

 

 

var item = items.getItem(itemIndex);

 

 

var checkbox = getItemCheckBox(item);

 

 

//Check whether the Item's CheckBox) is checked.

 

 

if (checkbox.checked) {

 

selectedItemsTexts += item.get_text() +

", ";

 

selectedItemsValues += item.get_value() +

", ";

 

}

}

selectedItemsTexts = selectedItemsTexts.substring(0, selectedItemsTexts.length - 2);

selectedItemsValues = selectedItemsValues.substring(0, selectedItemsValues.length - 2);

 

//Set the text of the RadComboBox with the texts of the selected Items, separated by ','.

 

combo.set_text(selectedItemsTexts);

 

//Set the comboValue hidden field value with values of the selected Items, separated by ','.

 

 

// document.getElementById("comboValue").value = selectedItemsValues;

 

 

if (selectedItemsValues == "") {

 

combo.clearSelection();

}

}

 

</script>

 

 

</telerik:RadCodeBlock>

 



thanking you in advance.
sateesh n

1 Answer, 1 is accepted

Sort by
0
Vesko
Top achievements
Rank 2
answered on 26 Mar 2010, 11:17 AM
The code is hardly readable pasted that way. Can you use the Format Code Block button please?
What is the exact problem?
Tags
ComboBox
Asked by
Sateesh kumar
Top achievements
Rank 1
Answers by
Vesko
Top achievements
Rank 2
Share this question
or