DevExpress TreeList settingSelection recursive - asp.net

ASPX
<dx:ASPxTreeList ID="ASPxTreeListLocations" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSourceUserMetersTree" KeyFieldName="sno" ParentFieldName="ParentId"
Width="300px" SettingsSelection-Recursive="true" Theme="Office2010Black">
<Columns>
<dx:TreeListTextColumn FieldName="Text" VisibleIndex="0" Caption="Lokasyon">
</dx:TreeListTextColumn>
</Columns>
<SettingsBehavior AutoExpandAllNodes="True" />
<SettingsSelection Enabled="True" />
</dx:ASPxTreeList>
<asp:SqlDataSource ID="SqlDataSourceUserMetersTree" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>">
</asp:SqlDataSource>
CODEBEHID
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSourceUserMetersTree.SelectCommand = "SELECT * FROM Tree";
ASPxTreeListLocations.DataBind();
}
QUESTION:
Codes are working well. I want to recursive selection, but this property is not working. If I define SqlDataSource selectCommand in aspx side, it works. I cant find any solution. No error message. Any advice?
Thanks...

Try to add the option recursive = "true" to your tree settings,
NP

Related

can't change selection after DDL get deafult value

am having a data based dropdownlist which the default selection is set by user session. it is working fine, but if i try to select a different item on the list after, its jump back to the default. am using visual studio 2015, web form, asp.net
i try selecting default item in 2 way and still the same problem
if (Session["plyer2"] != null) {
string DropDownListSelected = Session["plyer1"].ToString();
DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue(DropDownListSelected).Selected = true;
DropDownList2.SelectedValue = Session["plyer2"].ToString(); }
have been searching google for the last 2 day didn't find help
the DDL is autopostback
the code is in the .aspx.cs file: protected void Page_Load(object sender, EventArgs e)
the databind is in the .aspx file
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource5" DataTextField="forshow" DataValueField="forshow" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="1">בחר גארד</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [forshow] FROM [players] WHERE ([position] = #position)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="גארד" Name="position" QueryStringField="גארד" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
well its no a real answer to the problem, but since I'm using session to select item, i add
Session.Abandon();
so its cancelling the IF statement next page load and that's good enough for me

can't get checked nodes from RadTreeView in code behind

I have a rad tree view as below:
<telerik:RadTreeView ID="rtreevwParvandehShakhsi" runat="server" CheckBoxes="true" TriStateCheckBoxes="False" DataSourceID="SqlDataSource1" EnableViewState="true"></telerik:RadTreeView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:PigisConnectionString %>' SelectCommand="SELECT SCT_ParvandehShakhsi.*, ParvandehShakhsi_ID AS Expr1, ParvandehShakhsi_Code AS Expr2, ParvandehShakhsi_Desc AS Expr3, ParvandehShakhsi_ParentID AS Expr4, ParvandehShakhsi_Personel_ID AS Expr5 FROM SCT_ParvandehShakhsi WHERE (ParvandehShakhsi_Personel_ID = #personel_ID)">
<SelectParameters>
<asp:SessionParameter SessionField="user_personel_id" Name="personel_ID"></asp:SessionParameter>
</SelectParameters>
</asp:SqlDataSource>
<asp:Button ID="btnSubmitParvandehShakhsi" runat="server" Text="ثبت" OnClick="btnSubmitParvandehShakhsi_Click" CausesValidation="false" Font-Size="Medium" CssClass="btn green" Height="38px" Width="63px" />
and I want to get the checked nodes in code behind. i use below code but it dont get the checked node for me! where is the problem?
protected void btnSubmitParvandehShakhsi_Click(object sender, EventArgs e)
{
foreach (RadTreeNode tnode in rtreevwParvandehShakhsi.CheckedNodes)
{
RadWindowManager1.RadAlert("node value : " + tnode.Value, 330, 180, "پیام سیستم", null, null);
}
}
Try setting the DataSourceId of the treeview manually on Page_Load if it is not PostBack.
I think the treeview's datasource gets overriden on page load before the the button click event fires leading to CheckedNodes being empty.

How to set a asp:DropDownList SelectedValue to a Session Variable?

There are several articles describing how to do this is code behind however:
Is it possible to set the value of a dropdownlist to a session variable on the aspx page?
I am using SqlDataSource to populate the dropdownlist so do not wish to add code behind if it can be avoided.
<asp:DropDownList ID="ddl" runat="Server" DataSourceID="sqlDS" DataValueField="ID" DataTextField="TEXT" AppendDataBoundItems="true">
<asp:ListItem Text="" Value="" Selected="True" />
</asp:DropDownList>
<asp:SqlDataSource ID="sqlDS" runat="Server" SelectCommand="spDS" SelectCommandType="StoredProcedure" />
Set Session("ID") as selected value on load?
The dropdown list is already populated from the sqldatasource. I just want to set the initial value on page load.
You need a server side code in order to use Session. The following code doesn't requires code behind file, but again the code inside script will run at server side.
<asp:DropDownList ID="ddl" runat="Server"
DataSourceID="sqlDS"
DataValueField="ID"
DataTextField="TEXT"
AppendDataBoundItems="true"
OnSelectedIndexChanged="ddl_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Text="" Value="" Selected="True" />
</asp:DropDownList>
<asp:SqlDataSource ID="sqlDS" runat="Server"
SelectCommand="spDS" SelectCommandType="StoredProcedure" />
<script runat="server">
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
Session["SelecteValue"] = ddl.SelectedValue;
}
</script>
Note: Make sure AutoPostBack="True" for DropDownList.
Do not mix code with markup. It makes sense to separate them for many reasons. So ASPX will have just the presentation, and CS/VB just the code logic.
When you compile/deploy your side to production - there will not be "the second page" - only ASPX page will remain. Code will be compiled into a DLL.
you'll need an event for your dropdown list on change. Are you using C# or VB.net for your codebehind?
add to onSelectedIndexChanged="ddl_OnSelectedIndexChanged"
to your code behind add:
{this is C# vb is similar}
protected void ddl_OnSelectedIndexChanged(Object sender, EventArgs e)
{
Session["selectedID"] = ddl.selectedValue;
}
to your page load, add
if (isPostback)
{
ddl.selectedValue = Session["selectedID"];
}

PostBack DataBind error: "Ensure that the control is added to the page before calling DataBind."

I have a program that allows the user to use a few dropdowns to pick a topic and attribute, then the data are pulled that match on both of those conditions. In the gridview are a lot of templatefields use textboxes for instant editing (a submit button saves all changes) as well as a template with a dropdown bound to a parameter. This was all working hunky-dory for quite a while.
Then, we changed some of the data in the tables (keeping all the same field names) and now the page loads perfectly fine on launch but then as soon as you select something different in any of the drilldown dropdowns the page fails. I get an error saying
"The DropDownList control 'TagDDL' does not have a naming container.
Ensure that the control is added to the page before calling DataBind."
(TagDDL is the dropdown in the templatefield in gridview). If I simply remove this templatefield, I get a similar (though different) error on a hyperlinkfield, removing this gives me an error in a boundfield, so obviously it's not tied to any one thing.
My idea is that it has something to do with how databinding works on post-back, since the page loads perfectly initially, the dropdowns have 'Enable PostBack' and the error messages refer to DataBind. Any ideas?
The SqlDataSource that builds Gridview (leaving out the drilldown dropdowns for now)
<asp:SqlDataSource ID="MasterTable" runat="server"
ConnectionString="<%$ ConnectionStrings:spvConnectionString %>"
SelectCommand="exec pmtv2.maintable_display 1, #IPG_Assigned, #CompetitorName, #enterprise_zone, #Banner, #BrandName"
<SelectParameters>
<asp:ControlParameter ControlID="ChooseBanner" Name="Banner" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ChooseIPGs" Name="IPG_Assigned" PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="ChooseBrands" Name="BrandName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ChooseComps" Name="CompetitorName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ChooseZone" Name="enterprise_zone" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<div id="MasterDiv" style="width:90%">
<asp:GridView ID="MasterDisplay" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="productKey,banner,enterprise_zone,userID" DataSourceID="MasterTable"
OnRowDataBound="MasterDisplay_RowDataBound"
OnSorting="MasterDisplay_Sorting"
class="mGrid" AlternatingRowStyle-CssClass="mGridAlt">
</AlternatingRowStyle>
<Columns>
<asp:TemplateField HeaderText="Description" SortExpression="productdescriptionlong">
<ItemTemplate>
<a href="javascript:openPopup('JustinPractice4.aspx?UPC=<%# Eval("UPC") %>
&banner=<%# Eval("banner") %>&enterprise_zone=<%# Eval("enterprise_zone") %>')"><%# Eval("productdescriptionlong")%></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="BrandName" HeaderText="Brand"
SortExpression="BrandName" />
<asp:TemplateField HeaderText="New Price" SortExpression="new_base_retail">
<ItemTemplate>
<asp:TextBox ID="RWNextPrice" runat="server"
Text='<%# Bind("new_base_retail", "{0:N2}") %>' Width="60px"
class="calculate" onchange="lineItemRipple(this)"
Visible='<%# ShowBox %>'></asp:TextBox>
<asp:Label ID="RNextPrice" runat="server" Text='<%# Eval("new_base_retail", "{0:c}") %>'
Visible='<%# ShowLabel %>'></asp:Label>
<asp:HiddenField ID="lineCode" runat="server" Value='<%# Eval("line_code") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField DataImageURLField="unique_flags" HeaderText="Flags"
DataImageURLFormatString="Media/Images/{0}.png" SortExpression="unique_flags"/>
<asp:TemplateField HeaderText="Tag Type" SortExpression="tag_type">
<ItemTemplate>
<asp:DropDownList ID="TagDDL" runat="server"
DataSourceID="dimTags"
DataTextField="Tag_type_name"
DataValueField="Tag_type_name"
SelectedValue='<%#Bind("tag_type") %>'
visible='<%#ShowBox %>'>
</asp:DropDownList>
<asp:Label ID="TagR" runat="server"
Text='<%# Eval("tag_type") %>'
Visible='<%# ShowLabel %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Commit" runat="server" Text="Commit Changes" OnClick="Commit_Click"
class="button"/>
and the relevant code behind:
protected void Page_Load(object sender, EventArgs e) {
ErrorMsg.Text = "test45";
}
protected void MasterDisplay_RowDataBound(object sender, GridViewRowEventArgs e) {
DataSourceSelectArguments sr = new DataSourceSelectArguments();
DataView dv = (DataView)CheckForCommit.Select(sr);
if (dv.Count != 0) {
CommittedOrNot.Text = dv[0][0].ToString();
}
//pulling results from a SqlDataSource confirming presence of data
//calculations to maintain a running tally of certain fields for later use
}
protected void Commit_Click(Object sender, EventArgs e) {
string tagValue = "FLAG";
foreach (GridViewRow gvr in MasterDisplay.Rows) {
tagValue = ((DropDownList)gvr.FindControl("TagDDL")).SelectedValue;
MasterDisplay.UpdateRow(gvr.RowIndex, false);
} //for every row, update it
MasterDisplay.DataBind();
}
It was a simple error of trying to add to a DDL before I had actually pulled the data needed to bind it. Changing the order of things slightly did the trick
I am glad you found your answer. I had a similar issue on a UserControl (ascx) that was being loaded a run-time. I, too, had made a change to my data source and the corresponding sql data sources. (In my case, I was replacing the sql data sources with an entity model.)
What I found was that one of my controls would bind to the new data source (via the code behind) with no problems. The code looked as follows:
gridSomeData.DataSource = controller.GetListOfAssociatedParts();
gridSomeData.DataBind();
However, in the same method, the next section of code would fail when the DataBind() method was called. The code looked as follows:
drpDataList.DataSource = controller.GetListOfParts();
drpDataList.DataTextField = "PartID"
drpDataList.DataValueField = "PartKey"
drpDataList.DataBind();
It turned out, that when I removed the prior ASCX markup for the SqlDataSource objects, I failed to remove the reference in the DataSourceID attribute of the drop down control. So when I called the DataBind() method, the binding engine checked the attributes of the control, found a name DataSourceID, and immediately went looking for it in the control hierarchy of the UserControl. When the binding engine failed to find the object, it threw the exception "The DropDownList control [...] does not have a naming container..."
I will admit that this particular exception is somewhat misleading, as it is really the binder being confused over which instructions to follow for the data source (the code behind, or the markup in the ascx file).
I hope this helps with some perspective. :)

Grid view can't show result (using QueryExtender) when chosed an other Grid'view page

My page have a EntityDatasource
<asp:EntityDataSource ID="SearchEntityDataSource" runat="server"
ContextTypeName="CallSellSupport.DataAccess.supportCallEntities"
EnableFlattening="False" EntitySetName="Customers" Include="Area" OrderBy="it.CreatedDate DESC"
ConnectionString="name=supportCallEntities" DefaultContainerName="supportCallEntities">
</asp:EntityDataSource>
and QueryExtender
<asp:QueryExtender ID="SearchQueryExtender1" runat="server" TargetControlID="SearchEntityDataSource">
<asp:SearchExpression SearchType="StartsWith" DataFields="Phone">
<asp:ControlParameter ControlID="txtPhoneNum" />
</asp:SearchExpression>
<asp:SearchExpression SearchType="Contains" DataFields="FullName">
<asp:ControlParameter ControlID="txtCustomerName" />
</asp:SearchExpression>
</asp:QueryExtender>
and a GridView (allow paging)
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CustomerID" DataSourceID="SearchEntityDataSource"
AllowPaging="True" AllowSorting="True" CellSpacing="1"
PageSize="7"
I entered data into texbox, then I clicked button. Gridview display ok :)
But when I chosed Page 2 (or page 3, or page 4), then I enter data into textbox, and now, gridview doesn't display anything data, although I clicked button (many times...)
I think this problem is post back (because I change Gridview's page), but I can't find out a solution.
Hope somebody may help me...
Thanks a lot.
Please don't forget to back to the 1st page
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
}

Resources