I have master page named MPHome.master contains a RadComboBox here is the code of
<telerik:RadComboBox CheckBoxes="true" EnableCheckAllItemsCheckBox="true" ID="TaskID" runat="server" Height="100" Width="150" EmptyMessage="Select a Task"
EnableLoadOnDemand="true" OnClientItemsRequesting="OnClientItemsRequesting" WebServiceSettings-UseHttpGet="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true">
<WebServiceSettings Method="GetTasks" Path="~/ProjectDropDownWebService.asmx" />
</telerik:RadComboBox>
Now this combo works fine it fills values from webservice and also shows checkboxes on it.Now what I do is I inherit this master page to Default.aspx page and inside button of submit in default page I have used this code
protected void btnViewAllTask_Click(object sender, EventArgs e)
{
RadComboBox TaskID = (RadComboBox)Master.FindControl("TaskID");
var selectedtask = TaskID.CheckedItems;
}
This selectedtask returns me count of zero either i have selected all the records on it.
As far as I know. You are trying to use the CheckBoxes along with Load On Demand feature which is not a supported scenario with telerik RadComboBox with checkboxes=true.
Please find more details about this topic here.
Related
I want to preface this by saying that I am a beginner to asp.net, especially when it comes to working with the FormView controls. I have searched long and hard and have spent hours debugging this issue.
I have 3 FormViews on one aspx page. Each FormView has its own EditItemTemplate and PagerTemplate with DefaultMode="Edit". I am not using a SqlDataSource, but instead databinding programatically on the PageLoad when if(!Page.IsPostBack) and also calling the databinding method when the PageIndexChanging method is called. The pager template contains a 'Back' and a 'Next' button set with CommandArgument="Prev" and CommandArgument="Next", respectively, and both set with CommandName="Page".
The paging works great on the first FormView. When I hit the back or next button, it pages (i.e. re-binds) appropriately. During the 1st FormView's paging event, I also successfully call the binding methods for the 2nd and 3rd FormView since I want them to bind data that is specific to the page selected in the 1st FormView.
But, when I page back to the first page of the 1st FormView (i.e. PageIndex = 0), and then try to page forward in the 2nd FormView, the datakey for the 1st FormView is null. In fact, the formview1.DataSource is null for the 1st FormView when I try to click a navigation button on the 2nd FormView.
Then, here's where I thought it was weird, ... if I click back a second time on the 1st FormView, THEN the formview1.DataSource is fine, and I can then navigate in the 2nd FormView.
All viewstates for the formviews and the buttons are set to true.
I have tried calling formview1.DataBind() inside formview2's paging event before any paging occurs but no success there. I have also tried setting properties: UseSubmitBehavior="False" and CausesValidation="False" on the paging buttons. Admittedly, I did this without really understanding the behavior but rather implemented after seeing it suggested in solutions for other somewhat related problems.
The templates are rather long since there are many fields in each. But the FormView tags look like this:
<asp:FormView ID="fvHeader" runat="server" DataKeyNames="ObjectID" DefaultMode="Edit" AllowPaging="True" OnModeChanging="fvHeader_ModeChanging" OnPageIndexChanging= "fvHeader_PageIndexChanging">
<EditItemTemplate> ..... </EditItemTemplate> </asp:FormView>
PagerTemplates:
<PagerSettings Mode="NextPrevious" />
<PagerTemplate>
<span class="labels">Page: <%#fvHeader.PageIndex+1%> of <%#fvHeader.PageCount %></span>
<asp:Button ID="btnBack" runat="server" CommandArgument="Prev" CommandName="Page" CssClass="btnHdr" Text="<< Back" />
<asp:Button ID="btnNext" runat="server" CommandArgument="Next" CommandName="Page" CssClass="btnHdr" Text="Next >>" /> </PagerTemplate>
Note that 'fvHeader' is what I'm calling 'formview1' for simplicity in my question.
Back/Next buttons C# code and databinding the 1st formview:
protected void fvHeader_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
fvHeader.PageIndex = e.NewPageIndex;
bindFV_Initial();
//rebind fvSub1 (2nd formview) to get the 1st obs of the newly selected header record
fvSub1.ChangeMode(FormViewMode.Edit);
fvSub1.PageIndex = 0;
bindSub1_Initial();
//rebind 2nd subform
fvSub2.ChangeMode(FormViewMode.Edit);
fvSub2.PageIndex = 0;
bindSub2_Initial();
}
private void bindFV_Initial()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Open();
if (dtEOS == null || dtEOS.Rows.Count == 0)
{
sqlda = new SqlDataAdapter("USE dbWEF SELECT * FROM tblHeader WHERE [UserID] = '" + Session["User"] + "' AND [ProjectName] = '" + Session["Project"] + "'", conn);
sqlda.Fill(dtEOS);
}
fvHeader.DataSource = dtEOS;
fvHeader.DataBind();
conn.Close();
if (dtEOS.Rows.Count > 0)
{
fillDD_fvHeader(); //Fill dropdowns and databind ddls
}
}
}
Below is the error message I receive when I attempt to navigate the 2nd formview.
Error in: bindSub1_Initial.
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Collections.Specialized.OrderedDictionary.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKey.get_Item(Int32 index)
at RenewableEnergyDataEntry.Forms.EagleObservationSurvey.bindSub1_Initial()
During debugging, I find that this error occurs right when the 2nd formview is being binded because the datatable is empty which is a result of it needing the datakey from formview1 to pull the correct data, which again, is null because formview1's datasource goes to null. But clicking formview's back button one more time, refills and KEEPS the datasource, thereby allowing formview2 to fill and navigate perfectly. So strange...
I suggest you simplify you code.
more than likely you are creating conflicts with the view state.
We can't see where and how your dataSource: (dtEOS) is being defined.
But I am going to guess that it's being reset conditionally on a call back.
This is a common problem in ASP.net (conflict with view sate and /or databinding).
Try using a grid instead of a formview and it will handle the paging much more gracefully without needing a postback and data rebind.
I have an ASP.NET control with three listboxes: LBParent, LBChild1 and LBChild2.
LBParent has to be filled programmatically. I do this in Page_Load.
When the user selects a value in LBParent, I want to fill both LBChild1 and LBChild2 with some data, programmatically. The children lists must also keep track of their selected value.
Basically, the parent list is a list of users, the first list is a list of permissions the user has, the second list is a list of permissions the user doesn't have.
My plan is to add two buttons to move permissions between the two lists.
Unfortunately, I cannot get this to work properly.
If I populate the parent list in Page_Load, the selected index seems to reset. I used ViewState to save the index... but this seems to require an additional refresh, because it doesn't update after the PostBack. This is not acceptable.
If I populate the children listboxes on the OnParentSIC event, there is no way I can keep track of their selected index. The OnChildXSIC events never fire, because the listboxes get repopulated "too soon". (?)
How can I get this to work as intended? Maybe there is a better solution but I'd really like to understand how to get this solution to work, as I can't see a possible solution at the moment.
Control.ascx
<%# Control Language="C#" AutoEventWireup="true" EnableViewState="True" CodeBehind="..." Inherits="..." %>
<form runat="server">
<asp:ListBox ID="LBParent" runat="server" CssClass="form-control"
AutoPostBack="true" OnSelectedIndexChanged="OnParentSIC" />
<asp:ListBox ID="LBChild1" runat="server" CssClass="form-control"
AutoPostBack="true" OnSelectedIndexChanged="OnChild1SIC" />
<asp:ListBox ID="LBChild2" runat="server" CssClass="form-control"
AutoPostBack="true" OnSelectedIndexChanged="OnChild2SIC" />
</form>
Control.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
// Populate parent
for(...) LBParent.Items.Add(...);
}
The Onchange-event fires, but before that the OnLoad fires.
So:
The user clicks on an selection
A postback is triggered
At the server the Onload fires (and rebuilds the list)
The OnSelectedIndexChanged fires (which lost the selection by now)
So I would try to save the current-selected-index before you rebuild the list (in the Onload).
If you restore it later on while you are in the same 'postback' you can save it in a simple variable. No need to store in a Viewstate or Session.
use Like this
If You are on the Same Page then You can Use ViewState/Hidden Fields
to Maintain States
First Time Adding ListItem on PageLoad Use Like this
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
AddListItems();
}
}
Protected Void AddListItems()
{
// Populate parent
for(...) LBParent.Items.Add(...);
for(...) SecondList.Items.Add(...);
for(...) ThirdList.Items.Add(...);
}
I have a dropdownlist inside a template column on a obout grid. Currently i am populating the dropdownlist on page load with a sqldatasource. However, i now have to load the dropdownlist dependent on the value of a certain column. For example: If status = 1, i populate the dropdownlist with a list of available options that pertain to status 1.
<obout:Column ID="colStatus" DataField="wf_status_id" Align="center" HeaderText="Status" HeaderAlign="center" Width="130px" Wrap="true" runat="server" AllowGroupBy="true" AllowFilter="true">
<TemplateSettings EditTemplateId="tmpStatusIDEdit" TemplateId="tmpStatusID" />
</obout:Column>
<obout:GridTemplate runat="server" ID="tmpStatusID" >
<Template>
<%# Container.DataItem["Status"]%>
</Template>
</obout:GridTemplate>
<obout:GridTemplate runat="server" ID="tmpStatusIDEdit" ControlID="ddlStatus" ControlPropertyName="value">
<Template>
<obout:OboutDropDownList runat="server" ID="ddlStatus" Width="100%" Height="200" MenuWidth="215" DataSourceID="sdsStatus" DataTextField="wf_status_text" DataValueField="wf_status_id" />
</Template>
</obout:GridTemplate>
public void OnGridRowDataBound(object sender, Obout.Grid.GridRowEventArgs e)
{
if (e.Row.RowType == Obout.Grid.GridRowType.DataRow)
{
DropDownList ddlStatus = new DropDownList();
ddlStatus = (DropDownList)e.Row.FindControl("ddlStatus");
//LOAD DROP DOWN HERE//
}
}
When i attempt to execute this code, it shows that ddlStatus is null everytime. I have a tried a multitude of ways to get this and for some reason cannot seem to get it. Perhaps aother set of eyes or other ideas could help me out. Please let me know what it is i am doing wrong. Thank you ahead of time
UPDATE:DATABOUND EVENT CODE
<obout:OboutDropDownList runat="server" ID="ddlStatus" Width="100%" Height="200" MenuWidth="215" OnDataBinding="ddlStatus_DataBinding" DataSourceID="sdsStatus" DataTextField="wf_status_text" DataValueField="wf_status_id" />
protected void ddlStatus_DataBinding(object sender, EventArgs e)
{
Obout.Interface.OboutDropDownList ddl = (Obout.Interface.OboutDropDownList)(sender);
string statusID = Eval("wf_status_id").ToString();
}
I added the DataSource because i do not see another way to have the databinding event triggered.
I don't really know anything about obout controls but I have to assume they act very similar to the asp.net controls and have just been extended. With that assumption in mind, I will try and answer your question.
Your RowDataBound event has a few coding issues... for example, I am not sure why you are defining a new DropDownList and then trying to overwrite it with the next line. Also it sounds like the next line is returning null anyways.
First off I suggest not using the DataBound event at the row level. Use the control's DataBinding event as it will localize your code a lot better because you can trigger off the specific control's DataBinding and therefore not have to search for it. If your code changes (markup or codebehind) it is also a lot easier to change as it will not affect other things and there is less room for introducing bugs.
So I would make the following changes to address this:
Change your DropDownList definition to implement DataBinding:
<obout:OboutDropDownList runat="server" ID="ddlStatus" Width="100%" Height="200"
MenuWidth="215" OnDataBinding="ddlStatus_DataBinding" />
Then implement the OnDataBinding event (get rid of your DataBound event if you weren't using it for anything else):
protected void ddlStatus_DataBinding(object sender, System.EventArgs e)
{
// This will point to ddlStatus on the current row that is DataBinding so you
// don't have to search for it.
OboutDropDownList ddl = (OboutDropDownList)(sender);
// Now you can fill the DropDownList and set the default value how ever you like
...
}
You can also see this other question I answered a long time ago to see if it helps as it is doing the same thing but with a Repeater but it is pretty much the same thing as a grid:
Populating DropDownList inside Repeater not working
EDIT: Changed the code to use OboutDropDownList in the DataBinding.
you can find plenty of samples on obout knowledge base and examples. These should help you out: http://www.obout.com/combobox/aspnet_integration_grid.aspx, http://www.obout.com/grid/aspnet_ajax_cascading_comboboxes.aspx
(they refer to comboBox, but you can easily adapt them do a ddl)
I've a gridview with client ID, client name, client contact number and a hyperlink to client detail.
I would like to pass selected clint ID to another asp page (clientDetail.aspx & ClientContact.aspx).
I'm thinking of passing the clientID as session. But how do i go about doing this? Can someone guild me on this as im quite new to this.
& how do i use the passed data in clientDetail.aspx & ClientContact.aspx?
Thanks in advance for your help.
Add two new columns of type HyperLinkField to your gridView as follows. Now clientID is passed as QueryString. One link is here
<asp:HyperLinkField DataNavigateUrlFields="ClientID"
DataNavigateUrlFormatString="~/ClientDetails.aspx?id={0}"
Text="Client Details" />
Assuming that you are selected the grid row with a button or link button you could use the OnRowCommand event
When you wire into this event you can pick out the value you want from the selected item then save it into the Session which will then be available for subsequent pages. In the below exampel I've assumed the value is in a label field so you can pick it out of that control.
void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblMyValue = (Label)e.Row.FindControl("lblMyValue");
Session["myValue"] = lblMyValue .Text;
}
}
There are other variants of this for instance you could store the value you are interested in in the CommandArgument property of the button that you use to select the row. The command argument will then be available in the RowCommand event
void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
string arg = e.CommandArgument;
//.. put into session here
}
And there are alternatives using different events for instance you could use the DataKeys collection of the GridView to store the value you are interested in and pick out the value from there
Markup fragment
<asp:gridview id="CustomersGridView"
//.. more properties
datakeynames="myID"
onselectedindexchanged="MyGridView_SelectedIndexChanged"
runat="server">
Code behind
void MyGridView_SelectedIndexChanged(Object sender, EventArgs e)
{
int index = MyGridView.SelectedIndex;
Session["myValue"] = CustomersGridView.DataKeys[index].Value.ToString();
}
There are a number of alternatives to get this working. I would use the first one detailed if it were me - I've always found it easiest to get to work. You can make the label hidden with Css if you want - if it isn't suitable for the UI. Or use a hidden field (with runat="server"). I'm going to stop - I'm risking confusuing by just typing on.
You should be able to evaluate the clientid field of the asp.net gridview in the navgiate url of the hyperlink and pass it as a query string like so:
<asp:gridview id="OrdersGridView"
datasourceid="OrdersSqlDataSource"
autogeneratecolumns="false"
runat="server">
<columns>
<asp:boundfield datafield="ClientID"
headertext="Client ID"/>
<asp:boundfield datafield="ClientName"
headertext="Client Name"/>
<asp:boundfield datafield="ClientContact"
headertext="Client Contact"/>
<asp:hyperlinkfield text="Details..."
navigateurl="~\details.aspx?clientid='<%# Eval("ClientID") %>'"
headertext="Order Details"
target="_blank" />
</columns>
</asp:gridview>
I have a a generic control called dropdownlist.ascx that populates it's ListItems based on a XML document and a property that I pass to this control.
This control is used multiple times on the same aspx page. I have no problem casting this control as a DropDownList control in the Page_Load event of the aspx page, however when I want to set the SelectedValues of this control on the Page_Load event of the aspx page it doesn't work as the Items.Count value is 0.
I assume there are some Page Lifecyle issues going on here.
Control on page.aspx
<triangle:DDLResponse ID="ddlHeight" runat="server" CssClass="dropdownlist ddlregister" responseId="height" mode="dropdownlist" />
Codebehind on page.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
UserProfile profile = controls_session.profile;
DropDownList _ddlHeight = (DropDownList)ddlHeight.FindControl("dropdownlist");
_ddlHeight.SelectedValue = profile.Height;
}
}
The List Items of ddlHeight render without issue.
Anyone have any idea or solution to this?
Thanks,
Try to set the SelectedValue in Page_PreRender event. It will work.