How to filter second GridViewDataComboBoxColumn dropdown item from selection of first GridViewDataComboBoxColumn inside ASPxGridView - devexpress

There are two GridViewDataComboBoxColumn columns inside my ASPxGridView, Need to know that Selection of first GridViewDataComboBoxColumn dropdown item should filter the second GridViewDataComboBoxColumn item before pupulating data.
For example, If I choose 'India' from first GridViewDataComboBoxColumn then only India's cities must be populated in another GridViewDataComboBoxColumn dropdown using SqlDataSource.
My sample code:
<dx:ASPxGridView runat="server" ClientInstanceName="grid" AutoGenerateColumns="False" ID="ASPxGridView1" DataSourceID="DSEXTagList" OnCellEditorInitialize="GridViewEXTags_CellEditorInitialize" KeyFieldName="ID;" OnRowInserting="GridViewEXTags_RowInserting" Width="100%">
<Columns>
<dx:GridViewDataComboBoxColumn Caption="System" FieldName="System" VisibleIndex="1">
<PropertiesComboBox EnableCallbackMode="true" DataSourceID="DsSystem" TextField="SystemWithDescription" ValueField="System" NullDisplayText="Select System">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataComboBoxColumn Caption="Sub System" FieldName="SubSystem" VisibleIndex="2">
<PropertiesComboBox DataSourceID="DsSubSystem" TextField="SubSystemWithDescription" ValueField="SubSystem" NullDisplayText="Select Sub System">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
</Columns>
</dx:ASPxGridView>
Actually I'm new in Asp.net DevExpress technologies. Please somebody let me know what should I do in this case and fire event on selection of GridViewDataComboBoxColumn item in code side.

Check out this demo to see (play) this approach in action. See the demo's description for more information:
For the "parent" combobox column: handle the client-side "SelectedIndexChanged" event,
Call the "child: combobox column/editor callback via the client-side "PerformCallback" method,
Subscribe and Handle the "child" comobobox "Callback" event and reload its data.

Related

Update listview on dropdownlist change - using causes validations and commandName

I have a list of ListView Items of type Place{Id,Label}. In the last column, I have a DropDownList that helps me to select/set a new Label with the selected value.
Actualy I'm using a DropDownList and a Button
<asp:DropDownList CssClass="edit_place_combobox"
ID="CollectiveBanksDropDownList3" runat="server" AutoPostBack="False"
DataSourceID="BanksObjectDataSource1" DataTextField="PlaceLabel"
DataValueField="PlaceID" Height="22px" Width="217px" />
<asp:Button runat="server" CausesValidation="true" CommandName="updatelabel" />
This works but I want to delete the button and trigger update when the DropDownList changes.
Is this possible in webform ?
Drop down lists have "OnSelectedIndexChanged" which allows you to call a function in your backend code.
If your listview is wrapped with an update panel. All you need to do is call UpdatePanelName.Update() in the method you declared for "OnSelectedIndexChanged" in your dropdown list.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.onselectedindexchanged%28v=vs.110%29.aspx

getting the RadGrid checkbox column value in server

I have a RadGrid having a checkbox column, i have added the column as a ItemTemplate to make it editable in the regular mode.
<telerik:GridTemplateColumn UniqueName="IsSelected" DataField="IsSelected">
<ItemTemplate>
<asp:CheckBox ID="chkBoolean" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsSelected")) %>'Enabled='<%# Convert.ToBoolean(Eval("IsSelectionDisable")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
Using this I am able to display a checkbox as editable. Now my problem is how do i get the checked value of the checkox for saving it when the user has changed the checkbox. On click of a button i need to get all the rows that are still checked and save them. The below code does not work as it does not get the checkbox. Is there any way possible to get the value.
foreach (GridDataItem item in rgUnavailResult.MasterTableView.Items)
{
(CheckBox)item["IsSelected"].Controls[0]
}
Thanks
Found the checkbox
((System.Web.UI.WebControls.CheckBox)(item["IsSelected"].FindControl("chkBoolean")))

CheckBox in ASP.NET GridView template field does not retain it's value on submit

I'm trying to use CheckBoxes within a GridView's TemplateField to select multiple entries from that GridView. The GridView's data source is a list of items that is generated at page load.
<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False"
AllowPaging="True" onpageindexchanging="TANsGridView_PageIndexChanging"
DataKeyNames="GUID">
<Columns>
<asp:TemplateField ShowHeader="False" HeaderText="Checker">
<ItemTemplate>
<asp:CheckBox ID="SelectCheckbox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
The problem is that when I press a submit button, all the CheckBoxes are returned with the Checked property as 'false'.
For cycling through the rows, I use:
foreach (GridViewRow row in TANsGridView.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("SelectCheckbox");
}
What should I use in order to have access to the correct value?
Thanks, Catalin
Are you mistakingly rebinding the gridview on page load every time? The gridview binding code should be wrapped in a if statement ensuring it's only done on not postback.
Am I supposed to put this here for an accept check now? :)
if your are binding the grid on page load.load the grid like this.
if(!ispostback)
{
..........loading data to databind.
}

Dynamically adding a Button to a PlaceHolder in a DataGrid

I have basically something like this:
<asp:datagrid id="DGrid" runat="server" AutoGenerateColumns="false">
<asp:TemplateColumn HeaderText="Stuff">
<ItemTemplate>
<asp:PlaceHolder id="PH" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</asp:datagrid>
I need to add a Button to the PlaceHolder depending on the values of the data I am binding. At the moment I am adding the Button after the data is bound in Page_Load. The problem is that the data binding methods are not called in postbacks, so the Button disappears when I click on it.
Any suggestions on how to do this? Problem is that I need to know some attributes of the grid item to create the Button, so I cannot create it before the data has been bound.
How about subscribing to ItemCreated event?
Markup:
<asp:datagrid id="DGrid" runat="server" OnItemCreated="DGrid_ItemCreated" AutoGenerateColumns="false">...</asp:DataGrid>
Code-behind:
protected void DGrid_ItemCreated(object sender, DataGridItemEventArgs e)
{
var ph e.Item.FindControl("PH") as PlaceHolder;
// ...
}
UPDATE
Regarding the situation when the e.Item.DataItem is null on a postback: only the reliable information (e.g. databound control properties) is persisted across postbacks (if ViewState is enabled), the entire data items don't survive them. Therefore you have to manage the state by yourself. You can persist only the necessary data in a ViewState (and not the entire data items since it can blow it up).

Change value of control inside a gridview templatefield itemtemplate

hi I have this gridview like this.
<asp:DropDownList ID="triggerDropDown" runat="server" AutoPostBack="true" onselectedindexchanged="triggerDropDown_SelectedIndexChanged">
<asp:GridView ID="myGridView" run="server">
<Columns>
<asp:TemplateField HeaderText="Column 1">
<ItemTemplate>
<asp:DropDownList ID="myDropDown1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Column 2">
<ItemTemplate>
<asp:DropDownList ID="myDropDown2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
now, when I change my triggerDropDown I want to change also all of the DropDowns inside Column 1 how can I do that?
protected void triggerDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
// what should I do here?
}
Inside your event method you should access the DropDownList that resides within each row of the GridView. Doing this you can bind each DropDownList to whatever data you want.
This link shows you how to do that:
http://www.velocityreviews.com/forums/t191319-need-help-with-accessing-a-control-within-a-template-field.html
Basically:
Iterate over each row of your GridView;
Find the DropDownList control with something like:
DropDownList mddl = GridView.Rows[2].FindControl("myDropDown1");
Bind new data to mddl.
The gridview is very likely not what you want here. The way to change the value of a control contained in a row is usually through grabbing a handle to the desired control using e.Item.FindControl() from within the ItemDataBound event of the gridview.
The problem with your approach is that you're wanting a control outside of the gridview (triggerDropDown) to interact with a single row of the gridview. Do you want the first row, first column, last row, first column or first column for each of the items in the grid? It's probably better you take the target of your trigger dropdown and place it outside of the gridview and deal with it directly.
If you really intend to change items in a row in the grid consider doing so in the ItemDataBound event of the gridview and you'll find lots of examples out there.
Actually I can use GridViewRow :) I just have to find the GridViewControl and get its Rows attribute which is a GridViewRow and now I can do a foreach of each row.
foreach (GridViewRow gridViewRow in (this.FindControl("myGridView") as GridView).Rows)
{
// I can see all elements of my row here as if I am traversing on GridViewEvents
}

Resources