ASPxGridView -Custom Controls in DetailRow - asp.net

I try to have custom controls in a DevExpress grids detail row. When ever a row is expanded I would like to load data into those custom controls based on the Masters Key.
I am using the detailrow expended method.
protected void grid_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e)
if (e.Expanded)
{
int id = Convert.ToInt32(grd.GetRowValues(e.VisibleIndex, "ID"));
...
}
The problem is I don't know how to access the custom controls in the expended detail row. I don't see any Row or Items properties on the grid, which would have been with a FindControl().
Any one got a clue on how to get the detail row or even a row object?
Thanks!

Try this:
protected void grid_DetailRowExpandedChanged(object sender, ASPxGridViewDetailRowEventArgs e)
if (e.Expanded)
{
YourControlType yourcontrol = (YourControlType)grid.FindDetailRowTemplateControl(e.VisibleIndex, "YourControlName")
}

Related

How to add Data From a combobox to a gridview control

I want To add The selected product from the Combo box to the grid view.
I have tried it by adding it in list box and it did work but to be more flexible with it I want to try grid view
protected void Button1_Click(object sender, EventArgs e)
{
lbl.Text = Billing.SelectedItem.Text;
Get.Items.Add(Billing.SelectedItem.Text);
Billing.Focus();
}
I have used this code to add it in the listbox.. And now for more flexibility I want it to do with gridview.

Posted data in gridview where I was added control dynamically

I added controls (i.e. template column) dynamically in grid view and click on button (post back) then grid view populated existing data (i.e.posted data) twice separated by
protected void Page_Init(object sender, EventArgs e)
{
//on init recreated controls
// if (IsPostBack)
{
gvFirst.DataSource = GetData("select top 10 * from Project_Master");
gvFirst.DataBind();
}
}
Sounds like you might be using Auto-generated fields. In design view, click the smart tag on the gridview and click "edit columns." Then uncheck the checkbox that says "Auto-generate fields." I think this should fix your problem if I am understanding you correctly.

How to know which dropdownlist onchange event was triggerd in asp.net?

Im trying to do a rather simple practice project and i got stuck for a while now.
I have 3 dropdownlists
and 3 views.
I want to do:
check if the current dropdownlist has chosen a value then that dropdown has a value, hide that view and show the next view.
my problem:
I have one method for all 3 of my dropdownlists that gets called when a change occurs.
I need to check which one of these dropdownlists triggerd the change so that i know which dropdownlist value i need to check(if it is empty or not) and depending on the value i show/hide views.
If more info is needed just ask and Thanks!
On the function you probably have something like
protected void OnChangedEvent(object sender, EventArgs e) {
// code here
}
sender contains the dropdown list that fired the event. So:
protected void OnChangedEvent(object sender, EventArgs e) {
var ddl = (DropDownList)sender;
}
and ddl will be the dropdown list.

DotNetNuke ObjectDataSource.SelectMethod not being saved in viewstate

I'm using DotNetNuke 4.9.2 and am running into an odd issue.
I have a MultiView in the module that I'm developing, and in one of the views have a GridView that is bound to an ObjectDataSource.
In a separate view, i have several buttons that will switch the SelectMethod of the ObjectDataSource in the 2nd view and then set that view active. That all works fine, until the grid is sorted on the 2nd view - which causes a postback and the ODS somehow picks up its original SelectMethod. The SelectParameters that are assigned at the same time in the code-behind stick though.
Seems to me that the ObjectDataSource should be remembering the SelectMethod in viewstate, shouldn't it?
<asp:ObjectDataSource runat="server" ID="MyObjectDataSource" SelectMethod="MyFirstSelectMethod" TypeName="Whatever"></asp:ObjectDataSource>
protected void Button1_Click(object sender, EventArgs e)
{
MyObjectDataSource.SelectMethod = "MyNewMethod";
// more code here to change the parameters as well...
MyMultiView.SetActiveView(MyView2);
}
When I run that button click, the grid displays as expected. When I click on one of the column headers for the GridView and break in the page load to inspect the SelectMethod, it has reverted to the one declared in the markup.
Any suggestions as to what my problem could be here?
I'm guessing you've made sure that you're not resetting .SelectMethod when the page reloads?
I ended up working around the issue by just using a page property to hold the selectmethod, and then resetting it on each postback...
protected string MySelectMethod
{
get
{
return (string)ViewState["MySelectMethod"] ?? MySearchResultsDataSource.SelectMethod;
}
set
{
ViewState["MySelectMethod"] = value;
MySearchResultsDataSource.SelectMethod = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
MySearchResultsDataSource.SelectMethod = MySelectMethod;
}
}
protected void MyButton_Click(object sender, EventArgs e)
{
MySelectMethod = "MyNewMethod";
}
Still not sure why that SelectMethod prop doesn't stick on a postback in nuke. I'm sure this has worked fine for me in straight asp.net projects in the past...

Postback destroys user controls in my GridView columns

I have a ASP.NET GridView that uses template columns and user controls to allow me to dynamically construct the datagrid. Now I'm implementing the event handler for inserting a row. To do that, I create an array of default values and add it to the data table which is acting as a data source. However, when my OnLoad event is fired on postback, all my template columns no longer have the user controls. My gridview ends up just being all blank with nothing in it and my button column disappears as well (which contains the add row, delete row and save buttons).
My row add event just does this:
public void AddDataGridRow()
{
List<object> defRow = new List<object>();
for (int i = 0; i < fieldNames.Count; i++)
{
defRow.Add(GetDefaultValueFromDBType(types[i]));
}
dt.Rows.Add(defRow);
}
It is fired from a button in a user control that's implement like this:
protected void Button1_Click(object sender, EventArgs e)
{
((Scoresheet)(this.Page)).AddDataGridRow();
}
My on load event does a bunch of stuff on first run to set the GridView up but I don't run that again by using the IsPostBack property to tell.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Initialize();
}
Anyone have any hints as to why my user controls are vanishing?
You have to add the controls to the grid on every page_load, not just if it's (!Postback)
Do you have the EnableViewState=true on the usercontrols and the GridView?
Is the AddDataGridRow() method called by Initialize()? You basically have two options:
Bind the grid on every postback and do not use viewstate (performace loss)
Bind the Grid only the first time (if (!IsPostBack)), and make sure that your user controls keep their viewstate.
From your code, it is not clear whether the user controls keep viewstate and what they have in them. It is not even clear what is the execution order of the methods you've shown. There is no binding logic, so even if you keep adding rows, the grid may still not be bound. Please elaborate a bit and show the whole page codebehind.

Resources