On selected index change drop down list is not bind - asp.net

On drop down list selected Index Change i want bind Drop Down List according the condition.
I am doing this and data is showing if i am using break point but On Front End Drop Down List is not Bind. it shows blank.
My code is given below:
SqlParameter[] param6 = new SqlParameter[]
{ new SqlParameter("#status","drivershow"),
new SqlParameter("#FromDateWithStartTime",driverdate),
new SqlParameter("#dayvalue",dayvalue),
};
List<clsDropDown> assigneddriver = comnFunctionObj.getDropDownList(clsConstant.SP_GET_CAR_BOOKING_STATUS, param6);
ddldriver.Items.Clear();
for (int i = 0; i < assigneddriver.Count; i++)
{
if (!ddldriver.Items.Contains(new ListItem(assigneddriver[i].DisplayFieldText.Trim(), assigneddriver[i].ValueFieldText.Trim())))
{
ddldriver.Items.Add(new ListItem(assigneddriver[i].DisplayFieldText.Trim(), assigneddriver[i].ValueFieldText.Trim()));
}
}

Make sure you bind the data after adding items to DropDownlist as:ddldriver.DataBind();
ddldriver.Items.Clear();
for (int i = 0; i < assigneddriver.Count; i++)
{
// add items
}
// now bind the Data to the Dropdownlist
ddldriver.DataBind();
Check also if assigneddriver list is not null.

Related

Add Columns Dynamically at specific index to existing RadGrid

I have to add custom column runtime on specific location to exiting telerik grid.
string[] customColumns = ds.Tables[2].Rows[0]["CustomColumns"].ToString().Split(',');
int startIndex = 7;
for (int i = 0; i < customColumns.Length; i++)
{
GridBoundColumn NewColumn = new GridBoundColumn();
tableGrid.MasterTableView.Columns.AddAt(startIndex, NewColumn);
NewColumn.HeaderText = customColumns[i].Replace("[", "").Replace("]", "");
NewColumn.DataField = customColumns[i].Replace("[", "").Replace("]", "");
NewColumn.Visible = true;
NewColumn.FilterControlWidth = Unit.Percentage(70);
NewColumn.HeaderStyle.CssClass = "setHeader";
NewColumn.HeaderStyle.Width = 130;
NewColumn.AllowFiltering = true;
NewColumn.OrderIndex = startIndex;
startIndex++;
}
Using this block of code column added successfully at given location but when I used existing grid filter functionality then position of column is changed and even I can't see value in column.
You will need to define an OrderIndex for the columns, and when adding a new one to the grid, you will know which OrderIndex to use. Check out the Reordering columns programmatically article for your reference.

update edited cells within treetable after expand/collapse items

I have a treeTable with editable cells within the expanded rows. The editable cells get a dirty flag after editing (in the example the background color is set to red).
The problem i'm running into is that i found no certain way to update the dirty flag on expand/collapse (edited cells get the css class 'edited-cell').
At the moment the code looks like that:
// each editable textfield gets a Listener
textField.attachLiveChange(
var source = oEvent.oSource;
...
jQuery('#' + source.getId()).addClass(EDITED_CELL_CLASS, false)
// list with cell ids, e.g. "__field1-col1-row1"
DIRTY_MODELS.push(model.getId()) //*** add also binding context of row
)
// the table rows are updated on toggleOpenState
new sap.ui.table.TreeTable({
toggleOpenState: function(oEvent) {
...
this.updateRows() // see function below
}
})
// update Rows function is also delegated
oTable.addDelegate({ onAfterRendering : jQuery.proxy(this.updateRows, oTable)});
//http://stackoverflow.com/questions/23683627/access-row-for-styling-in-sap-ui5-template-handler-using-jquery
// this method is called on each expand/collapse: here i can make sure that the whole row has it's correct styling...
// but how to make sure that special cells are dirty?
function updateRows(oEvent) {
if (oEvent.type !== 'AfterRendering'){
this.onvscroll(oEvent);
}
var rows = this.getVisibleRowCount();
var rowStart = this.getFirstVisibleRow();
var actualRow;
for (var i = 0; i < rows; i++){
actualRow = this.getContextByIndex(rowStart + i); //content
var row = this.getRows()[i]
var obj = actualRow.getObject()
var rowId = row.getId()
updateStyleOfRows(obj, rowId, actualRow)
updateDirtyCells(rowId) //*** how to get the binding context in this function???
}
};
// update Dirty Cells in function updateRows():
function updateDirtyCells(rowId){
for (var i = 0; i < DIRTY_MODELS.length; i++){
var dirtyCellId = DIRTY_MODELS[i]
//*** make sure that only the correct expanded/collapsed rows will be updated -> depends on the bindingContext of the row
jQuery('#' + rowId).find('#' + dirtyCellId + '.editable-cell').addClass(EDITED_CELL_CLASS, false)
}
}
This doesn't work correctly, because the ids of the cells change on each layout render (e.g. collapse/expand rows). Please see attached image.
Let me know if i should provide more information.

How to select only first 100 rows on Gridview

I have gridview that contains check boxes in one of the columns, then there is a "Select ALl" button which when clicked has to check top 100 CBs on the list, the client specifically stated they do not want pagination, it much easier to do this with pagination and display only 100 records per page then when the select all button is clicked everything on the given page gets selected however this is not what the client wants
Here is my code:
foreach (GridViewRow row in dgridTransactions.Rows)
{
for (int x = 0; x <=100;x++ )
{
var oneTransaction = (CheckBox)row.FindControl("chkAssigned");
oneTransaction.Checked = true;
}
}
If you want to run first hundred rows you only need this loop
for(int x = 0; x < 100; x++)
{
GridViewRow row = dgridTransactions.Rows[x];
// then manage row properties
CheckBox cb = (CheckBox)row.FindControl("chkAssigned");
cb.Checked = true;
}
using RowIndex you can keep track of row number.
foreach (GridViewRow row in dgridTransactions.Rows)
{
if(row.RowIndex<100 )
{
var oneTransaction = (CheckBox)row.FindControl("chkAssigned");
oneTransaction.Checked = true;
}
else
break;
}
There is issue in your code
You can use the below code
int x=0;
foreach (GridViewRow row in dgridTransactions.Rows)
{
if(x<100 )
{
var oneTransaction = (CheckBox)row.FindControl("chkAssigned");
oneTransaction.Checked = true;
}
else
break;
x++;
}
The foreach (GridViewRow row in dgridTransactions.Rows) loop runs for each row in your grid.
and in that you are using for (int x = 0; x <=100;x++ ){ which runs 100 times for every row.
You can use jquery or javascript for this Here is a JSFiddle which can help you
How about:
foreach (GridViewRow row in dgridTransactions.Rows.Cast<GridViewRow>().Take(100)) {
CheckBox cb = row.FindControl("chkAssigned") as CheckBox;
if (cb != null)
cb.Checked = true;
}
This will give the first items up to 100, so if you only have 90, it will give 90.
The diferent way of casting will also give you an additional security measure in case it fails to find the control. A direct cast will just throw an exception, which is always heavier then checking if the castes object is not null...
If you dont care about the cast verification, you can just inline everything into this:
dgridTransactions.Rows.Cast<GridViewRow>().Take(100).ToList().ForEach(x => ((CheckBox)x.FindControl()).Checked = true);

How to delete rows from a wijmo grid in a loop and refresh?

Is there a way we can delete rows from a wijmo grid running within a loop and refresh the grid with new data. I tried with the following approach, I can see the rows getting deleted while debugging but after the loop ends the grid is refreshed with old set of data.
self.delete = function (obj, event) {
var pagesize = $("#pageDisplay :selected").val();// 5
var pageSizeDiff = defaultPageSize - pagesize;//5
var $grid = $("#Grid");
var newData = $grid.wijgrid("data");// array of 10 objects
var i = 0;
while (i < pagesize) {
newData.splice(pageSizeDiff, 1);// delete from 5th row
$grid.wijgrid("data", newData);
//refresh grid
$grid.wijgrid("ensureControl", true);
i++;
};
};
I am not sure why you are setting the new data in the loop. Ideally, you should delete the rows in the loop and then, set the new data.

Calculate the sum of a datagrid's rows

I have this datagrid which has columns with a NumericStepper as an itemEditor where the user can change the number of items he wants to buy. How can I calculate the sum of all cells when the user updates datagrid's values?
EDIT 1
My datagrid is about colors and sizes of a product. The columns are generated dynamically from this function
private function getColumn(dataField:String, headerText:String,editable:Boolean) : DataGridColumn
{
var column:DataGridColumn = new DataGridColumn(dataField);
column.headerText = headerText;
column.width = 20;
editable ? column.editable = true : column.editable = false;
column.editorDataField = "value";
column.itemEditor = new ClassFactory(ColorSizesFormRenderer);
return column;
}
and then I loop my xml http result
for each (var thisSize:XML in result.product.(#id == pId)..size) {
_columns.push(getColumn("size"+thisSize,thisSize,true));
}
So how can I find the sum of all cells?
EDIT 2
I use this code to loop all my cells
protected function color_sizes_itemFocusOutHandler(event:DataGridEvent):void
{
total = 0;
for each(var row:Object in color_sizes.dataProvider) {
total += row.size28;
}
}
the row.size28 is generated dynamically. So it could be row.size29,row.size30 etc.
How can I loop through all my cells without knowing their data.property?
Thanks in advance
Your numeric stepper should show a bindable property value from the [data] row you display.
Then you just parse the dataProvider of the datagrid and make the sum of that data.property.
for ex:
class MyObject
{
[Bindable]
var itemsNo:int = 0;
var productName:String = "";
}
The datagrid will have a NumericStepper custom column that will take the value of {data.itemsNo}
At the end just count all itemsNo from the datagrid.dataProvider items

Resources