I am creating a dropdownlist called "ddlYears" dynamically like below code:
private void CreateDynamicDDL()
{
ddlYears.Items.Clear();
ddlYears.Items.Add(new ListItem("Year","0"));
for (int k = 0; k < 4; k++)
{
int time = int.Parse(DateTime.Now.Year.ToString());
ddlYears.Items.Add(new ListItem((time-k).ToString(),(k+1).ToString()));
}
}
and I have ddl selectedindexchanged event as below:
protected void ddlYears_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write(ddlYears.SelectedValue.ToString());
Response.End();
}
In the above code I am trying to write the selected value. But it's working fine, if select the second item which is "2010" (I mean returning selected value as 1) and so on, but if I select first item which is "Year" it's not firing that ddlYears_SelectedIndexChanged event. Please somebody help me
Thanks
If you have "Year" as the first item then by default it is already selected. If you drop down the list and re-select it, it won't call the SelectedIndexChanged method.
Does it work if you select 2010 and then select Year again?
Related
I have the MouseDown Event on my XtraGrid, that doesn't want to fire the second time on the same column.
It recognizes the first click, but unless I click another column or row before attempting to click the original row/column, nothing happens.
Can anyone tell me what I am missing? Here is the code in the MouseDown event:
var hitInfo = gridViewSpecialty.CalcHitInfo(e.Location);
if (hitInfo.InRowCell)
{
int nRow = hitInfo.RowHandle;
GridColumn column = hitInfo.Column;
LinkClick(nRow, column);
}
Thanks!! Bob
It's most likely due to the event erroring out. I'd be willing to bet if you put a Try{}catch{} around that statement, you may trap the error.
Here's what I use when trying to capture a user click event with a grid. I use the double-click event, like so:
private void gcMainGrid_DoubleClick(object sender, EventArgs e)
{
try
{
GridControl gc = (GridControl)sender;
DevExpress.Utils.DXMouseEventArgs dxMEA = (DevExpress.Utils.DXMouseEventArgs)e;
GridView gv = (GridView)gc.MainView;
int iRowHandle = gv.CalcHitInfo(dxMEA.X, dxMEA.Y).RowHandle;
//Check to see if the user is on a row.
if (iRowHandle >= 0)
{
//Do something here.
}
catch(Exception ex)
{
if (Debugger.IsAttached)
Debugger.Break();
else
throw(ex);
}
}
That will get me the RowHandle of the row that the user clicks on. I think that's what you're after but I wouldn't use the mouse-down event for that.
I have 2 columns I'm working with in an XtraGrid. When Column1's value changes, I'd like to perform some logic and possibly change the value of Column2 and disable Column2 as well. You can see my code below, but I have 3 problems:
My CustomRowCellEdit function seems to run non-stop in the background.
The SetRowValue on Column2 doesn't seem to really happen unless I click away from the row; I need the change to happen as soon as Column1 is changed.
How can I disable within my IF block?
I've added the following Event to a Grid:
this._myGridView.CustomRowCellEdit +=
new DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventHandler(
this.myGridView_CustomRowCellEdit);
Here is the Event:
private void myGridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
if (e.Column.FieldName == "Column1" && e.RowHandle >= 0)
{
GridView gv = sender as GridView;
string value1 = gv.GetRowCellValue(e.RowHandle, gv.Columns["Column1"]).ToString();
if (value1 == "something")
{
gv.SetRowCellValue(e.RowHandle, gv.Columns["Column2"], someOtherValue);
// I'd like to disable Column2 in this IF logic.
}
}
}
In the DevX docs, there is a note about the CustomRowCellEdit event that says
Due to the XtraGrid control's infrastructure, the CustomRowCellEdit event fires frequently - each time a cell is refreshed. Therefore, do not implement complex logic for your CustomRowCellEdit event handler...
Given your stated requirements, my approach would be to use the CellValueChanged event instead of CustomRowCellEdit. Your handler could then say something like
private void myGridView_CellValueChanged(object sender, CellValueChangedEventArgs e) {
if (e.Column.FieldName != "Column1") return;
GridView gv = sender as GridView;
if (e.Value == "something") {
gv.SetRowCellValue(e.RowHandle, gv.Columns["Column2"], someOtherValue);
}
}
To make an individual cell non-editable at runtime, see this topic on the DevExpress support site.
how to set readyonly for rows at runtime using Devxpress Grid Contorl.
Essentially what you need to do is handle the grid view's ShowingEditor event, and using the FocusedRowHandle and FocusedColumn properties, decide whether or not to allow editing for the current cell. To disable editing, set the Cancel property of the CancelEventArgs to true.
Hope this helps.
I have two pre populated combo boxes with value = “ID” and Text = Relevant data...
I am doing an edit in a grid view and I adjusted the template to have the two combo boxes (each relevant field has its own).
I have searched high and low and I assume this is so easy people don’t even ask about it... but if you see below the combo boxes do not populate the parameters with the value of the combo boxes.
So I have tried this:
protected void aspxGridviewUsers_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
e.NewValues["StoreID"] = GetStoreID();
e.NewValues["GroupID"] = GetGroupID();
}
protected int GetStoreID()
{
ASPxComboBox CBID = new ASPxComboBox();
CBID = aspxGridviewUsers.FindEditFormTemplateControl("ASPxComboBoxStoreEdit") as ASPxComboBox;
return Convert.ToInt32(CBID.SelectedItem.Value.ToString());
}
protected int GetGroupID()
{
ASPxComboBox CBID = new ASPxComboBox();
CBID = aspxGridviewUsers.FindEditFormTemplateControl("ASPxComboBoxGroupEdit") as ASPxComboBox;
return Convert.ToInt32(CBID.SelectedItem.Value.ToString());
}
This did not work. What am I doing wrong here?
How can I use those values in the comboboxes to update against my update statement?
I would suggest that you use the following code:
return Convert.ToInt32(CBID.Value);
code. Does it work for you?
When I am tryng to pass the gridview cell values to an array everything is perfect but the array is empty after executing the code.
When I see through debug mode the index of selected row also is fine, i.e. when I select two rows using checkbox among 1000 the count shows exactly 2 in the array but the data is empty.
I'm not able to get the cell value from the gridview.
Any advice would be greatly appreciated.
protected void Button2008_Click(object sender, EventArgs e)
{
ArrayList checkedItems = new ArrayList();
foreach (GridViewRow row in this.GridView1.Rows)
{
if (((CheckBox)row.FindControl("cbRows")).Checked == true)
{
checkedItems.Add(row.Cells[12].Text);
}
}
Session["CheckedItems"] = checkedItems;
Response.Redirect("About.aspx", true);
}
you can use a breakpoint and check where the problem is occuring, for instance, does row.Cells[12].Text show any value ?
and you can check how your aspx page is acting after the postback.
I am playing about just now trying to teach myself a little bit about the entity framework.
I have a Gridview data bound to a Entity Date Source using the Entity Framework. If I select certain items in that list I then wish to redirect another page and populate another gridview with just the items selected (but with more detail, different includes/navigation properties)
This is probably the most simple thing but I have spent 2 hours banging my head on the wall trying to get this to work.
Essentially I have a continue button which when clicked should identify all the UIDs (a column in the gridview) of the rows and allow me to subset to just these rows and pass them to another page to be rebound to another datagrid
Any ideas???
Well, the big picture is that you should get those IDs, pass them to the other page, and then use a query with Contains; see this question for an idea of how to use it:
How search LINQ with many parametrs in one column?
Assuming you haven't used DataKeys in your GridView, this would be my approach.
Page 1
protected void Button1_Click(object sender, EventArgs e)
{
var checkedItems = new List<int>();
foreach (GridViewRow row in GridView1.Rows)
{
var checkbox = (CheckBox)row.FindControl("CheckBox1");
if (checkbox.Checked)
{
checkedItems.Add(int.Parse(row.Cells[1].Text));
}
}
Session["checkedItems"] = checkedItems;
Response.Redirect("Page2.aspx");
}
Page 2
protected void Page_Load(object sender, EventArgs e)
{
var checkedItems = (List<int>)Session["checkedItems"];
Session["checkedItems"] = null;
foreach (var checkedItem in checkedItems)
{
Response.Write(checkedItem);
}
}
Using the IDs in the checkedItems List you can now query those from you DB and finally assign the Result to your GridView on the second page.
Instead of using Session you could pass the IDs via QueryString.