Devexpress combo: Can't set SelectedIndex higher than 99 on clientside - asp.net

I use a performCallback to add a new item to my ASPxCombo on serverside, and want to change my index to that new item on the client side. I use DevExpress onEndCallback to do this and it is working great if my index is <= 99. Above that the index is not changed.
Do anybody no if DevExpress's SetSelectedIndex() method works with index greater than this, seems a little strange to me.
<dx:ASPxComboBox runat="server"
ID="CmbManufacturer"
ClientInstanceName="cmbManufacturer"
CssClass="dxeButtonEdit_LWDisplayEdit_CustomDropDown"
DropDownStyle="DropDownList"
EnableCallbackMode="True"
OnCallback="CmbManufacturer_Callback"
ValueType="System.String"
FieldName="ID"
TextFormatString="{0}"
FilterBy="Name"
TextField="Name"
ValueField="ID"
EnableSynchronization="False"
AllowEdit="false"
ValidationSettings-Display="None"
AutoPostBack="False"
Visible="False"
Width="400" >
<ClientSideEvents SelectedIndexChanged="function(s,e) {OnManufacturerChanged(s,e); }"
Init="function(s,e) {LwValidating2(s,e);}"
EndCallback="function(s,e) { OnEndCallbackCmbManufacturer(s,e); }"/>
</dx:ASPxComboBox>
function OnEndCallbackCmbManufacturer(s, e) {
var index = s.cpSelectedIndex;
s.SetSelectedIndex(index);
OnManufacturerChanged(s, e);
}

I have solved the problem by moving my new Item in dropdownItemList up in front of list below CallbackpageSize. Then i can change index on combo to the Items new index.
protected void CmbManufacturer_Callback(object source, CallbackEventArgsBase e)
{
var manufacturerName = e.Parameter.Trim();
// need to move item to top of list because it must be lower than CallbackPagesize to work
int indexforNewItem = 1;
try
{
int newManufacturerId = SoftwareManufacturer.Update(-1, manufacturerName, "");
LoadDropDownBoxManufacturer(null);
int newManufacturerIndex = CmbManufacturer.Items.IndexOfText(manufacturerName);
CmbManufacturer.Items.Move(newManufacturerIndex, indexforNewItem);
CmbManufacturer.JSProperties["cpSelectedIndex"] = indexforNewItem;
}
catch ()
{
}
}

Related

ASPxGridview get row data from server-side

I'm working on a DevExpress Gridview and I want to get the data of the selected row (only one row can be selected at the time). I'm working on the Server-Side and I'm using FocusedRowChanged function.
EDIT: The FocusedRowChanged fire but nothing happen and the textboxes do not change value
protected void dxgrDepartement_FocusedRowChanged(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(GetType(), "FetchData", "<script language='javascript'>FetchData('4654654646')</script>");
txtDescription.Text = "patate";
//txtComments.Text = dxgrDepartement.GetRowValues(dxgrDepartement.FocusedRowIndex, "IdDepartment").ToString();
}
And the "FetchData :
function FetchData(text) {
//ClearField();
document.getElementById("<%= txtDescription.ClientID %>").value = text.toString();
}
BTW - Changing the callbacks property made no difference for us. We needed callbacks for other functionality so couldn't turn this off anyway.
The GetRowValues method did not work either.
This is a technique described on DevExpress' web site and it worked for us as long as we didnt use DevExpress' controls (ASPxDateEdit, ASPxTextBox):
ASPX page:
<dxwgv:GridViewDataTextColumn Caption="Dist. %" FieldName="DistributionPerc" VisibleIndex="3"
Width="50px">
<DataItemTemplate>
<asp:TextBox ID="txtDistPerc" runat="server" Text='<%# Eval("DistributionPercent") %>'
Width="50px" />
</DataItemTemplate>
</dxwgv:GridViewDataTextColumn>
Code behind:
for (int i = 0; i < grdHistory.VisibleRowCount; i++)
{
TextBox textbox = grdHistory.FindRowCellTemplateControl(i, grdHistory.Columns["DistributionPerc"] as GridViewDataColumn, "txtDistPerc") as TextBox;
var anything = textbox.Text;
}
Use:
gridView.GetRowValues(gridView.FocusedRowIndex, columnFieldName1, columnFieldName2, ..., columnFieldNameN)
Method ASPxGridView.GetRowValues
Property ASPxGridView.FocusedRowIndex
grid.EnableCallback = false; solved my problems!

Filtering the Ajax combobox in asp.net

I am using Ajax toolkit with a combobox functionality, the items being displayed are around 40,000, so I want to apply a filter on the same, so that a user types an alphabet in the combobox and corresponding entries with starting alphabet "a" will be displayed in the combobox.
Can I have an idea, I am not using Radcombobox, it is a simplest combobox.
<asp:ComboBox ID="AppComCombx" runat="server"
CssClass="dropdownpersonal textfont"
onselectedindexchanged="AppComCombx_SelectedIndexChanged" AutoPostBack="true">
</asp:ComboBox>
Try this : AutoCompleteMode = "SuggestAppend"
Like this
<ajaxToolkit:ComboBox ID="ComboBox1" runat="server"
AutoPostBack="False"
DropDownStyle="DropDownList"
AutoCompleteMode="SuggestAppend"
CaseSensitive="False"
CssClass=""
ItemInsertLocation="Append" />
For more info go here
Add to the ScriptManager reference on js file with script below and use Suggest or None mode for combo
Sys.Application.add_load(function () {
Sys.Extended.UI.ComboBox.prototype._ensureHighlightedIndex = function () {
// highlight an index according to textbox value
var textBoxValue = this.get_textBoxControl().value;
// first, check the current highlighted index
if (this._highlightedIndex != null && this._highlightedIndex >= 0
&& this._isExactMatch(this._optionListItems[this._highlightedIndex].text, textBoxValue)) {
return;
}
// need to find the correct index
var firstMatch = -1;
var ensured = false;
var children = this.get_optionListControl().childNodes;
for (var i = 0; i < this._optionListItems.length; i++) {
var itemText = this._optionListItems[i].text;
children[i].style.display = this._isPrefixMatch(itemText, textBoxValue) ? "list-item" : "none";
if (!ensured && this._isExactMatch(itemText, textBoxValue)) {
this._highlightListItem(i, true);
ensured = true;
}
// if in DropDownList mode, save first match.
else if (!ensured && firstMatch < 0 && this._highlightSuggestedItem) {
if (this._isPrefixMatch(itemText, textBoxValue)) {
firstMatch = i;
}
}
}
if (!ensured) {
this._highlightListItem(firstMatch, true);
}
};
});
AutoCompleteExtender is better choice in this case as all the way ComboBox will render all items on a page

Create Asp.net Reset Button

Is there any ways to create reset button to clear all text in text fields in asp form? When user hits the reset button, all text entered by them will clear and they are enable to enter back text in the area.
As per my knowledge there is no such reset functionality provided by Asp.Net.
We can achieve the reset like this
btnReset.Attributes.Add("onClick", "document.forms[0].reset();return false;");
Or
Like this
<input type='button' id='resetButton' value='Reset' onclick='theForm.reset();return false;'/>
Or OnClientclick of asp.net button use this theForm.reset();return false;
try this create a button with reset and in click event write ClearInputs(Page.Controls); and event will call this method.
protected void Button2_Click(object sender, EventArgs e)
{
ClearInputs(Page.Controls);
}
void ClearInputs(ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
((TextBox)ctrl).Text = string.Empty;
ClearInputs(ctrl.Controls);
}
}
In the button click method, set all textbox.text.length values to 0. either do it one by one, which is the simple way, or do it by getting all controls of type textbox on the page, which is tad bit more sophisticated, but could be much less typing, depending on the number of textboxes. Definitely more maintainable.
private void ChangeBtn_Click(object sender, EventArgs e)
{
foreach(Control c in Page.Controls)
{
if (c.Controls.Count > 0)
{
foreach(Control c2 in c.Controls)
{
if (c2.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
myspan.InnerHtml = ((TextBox)c2).Text;
((TextBox)c2).Text = ""; //or ((TextBox)c2).Text.Length = 0;
}
}
}
}
}
http://msdn.microsoft.com/en-us/library/20zys56y(v=vs.90).aspx
Create a Click event to the Button control and use the following codes below:
foreach (Control control in Page.Controls)
{
if (control is TextBox)
{
TextBox txt = (TextBox)control;
txt.Text = "";
}
}
This will save you some time to clear all the textboxes inside the web form.
Use Jquery the easiest way to find any type of control and will not have post back event.
$('input[type=text], textarea')
Use foreach loop for clearing value.
Please note that
btnReset.Attributes.Add("onClick", "document.forms[0].reset();return false;");
will not work in clearing pages that are posted back, i.e. If a text box had a value "Silly me" and has been posted back, this code will reset to the post back value which is "Silly me".
The workaround is to repost the page with cleared values - try the following code (it worked for me)
OnClientClick="document.location.href=document.location.href;"
will reload the page with cleared values...
I have multiple type of inputs in my page (TextBox, DropDownList and CheckBox), so here is how I reset them all
Put an <asp:Panel> that wraps my inputs
Run BtnClear_Click on Clear button click
Loop each inputs and reset text/selection/checked value by types
The codes
Default.aspx
<asp:Panel ID="PanelReport" runat="server">
...
<asp:TextBox ID="fldSpeedoMula" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddlPlateNo" runat="server" CssClass="form-control"></asp:DropDownList>
<asp:CheckBox ID="cbCard" runat="server" />
<asp:CheckBox ID="cbCash" runat="server" />
<asp:Button ID="BtnClear" runat="server" Text="Clear" CssClass="button" OnClick="BtnClear_Click"/>
...
</asp:Panel>
Default.aspx.cs
protected void BtnClear_Click(object sender, EventArgs e)
{
// Clear all inputs
foreach (DropDownList ddl in PanelReport.Controls.OfType<DropDownList>())
{
ddl.SelectedIndex = 0;
}
foreach (TextBox fld in PanelReport.Controls.OfType<TextBox>())
{
fld.Text = string.Empty;
}
foreach (CheckBox cb in PanelReport.Controls.OfType<CheckBox>())
{
cb.Checked = false;
}
}

How to get selected row of detail grid in Master-Detail GridView?

I'm having a problem on getting the selected rows values of a detail grid. I have master-detail grid in a popup control and it works fine. I also enabled the enable selection to have checkboxes but when i try to run GetSelectedFieldValues on ClientSideEvents of a button it always returns "0". What do i do wrong, i couldn't find it?
Here is the detail grid:
AutoGenerateColumns="False"
CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
CssPostfix="Aqua"
OnBeforePerformDataSelect="gv_ParameterTempD_BeforePerformDataSelect"
ClientInstanceName="gvC_ParameterTempD">
<dxwgv:GridViewCommandColumn
ShowSelectCheckbox="True"
VisibleIndex="0">
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataTextColumn
Caption="Detay Kodu"
FieldName="PrmDetailCode"
VisibleIndex="0">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn
Caption="Seçim Adı"
FieldName="PrmDetailName"
VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn
Caption="Seçim Adı(Grup)"
FieldName="PrmDetailNameG"
VisibleIndex="3">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn
Caption="Seçim Adı(Stok)"
FieldName="PrmDetailNameS"
VisibleIndex="4">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn
Caption="Grup Seçimi Yapan"
FieldName="PrmGroupSelector"
VisibleIndex="5">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn
Caption="Stok Seçimi Yapan"
FieldName="PrmStokSelector"
VisibleIndex="6">
</dxwgv:GridViewDataTextColumn>
</Columns>
And this is the button:
<ClientSideEvents Click="function(s,e)
{
pcc_Question.Hide();
gvC_ParameterTempD.GetSelectedFieldValues('PrmDetailName;PrmDetailNameG;PrmDetailNameS',ShowCellValue);
}"
/>
</dxe:ASPxButton>
and this is the jsscript:
function ShowCellValue(values) {
var value = condition.GetText();
alert(values.length); // here it returns "0"
if(value != "")
{
var newValue = ' ' + value + values + ' = ';
condition.SetText(newValue);
}
else
{
for(var i = 0; i < values.length; i ++) {
value += values[i];
}
condition.SetText(value);
}
}
I don't know what i do wrong,
Thanks for the help
Am I right in my assumption that the button is residing in the same DetailRowTemplate container? Anyway, it is necessary to access the proper instance of the detail GridView object. To do this, set the grid's ClientInstanceName property to a dynamic value. This should allow you to access the proper grid instance and fetch selected row values. A sample code is available at:
http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=Q90007
I'm setting the DataSource at Runtime but i do not call DataBind method, because it makes BeforePerformDataSelect of the Detail Grid to perform more than one.
This code set the master grids datasource and bind it:
protected void
gv_Answers_CustomCallback(object
sender,
ASPxGridViewCustomCallbackEventArgs e)
{
ConfPrmMTempCollection _ConfPrmMTempCollection = new ConfPrmMTempCollection();
masterKey = e.Parameters;
if (masterKey != "")
{
man.Add(new SqlOperatorEquality("MAND_CONF_PRM_M_TEMP.PARAMETER_M_TEMP_ID", Convert.ToInt32(masterKey)));
gv_Answers.DataSource = gc.LoadCollectionFromCollType(typeof(ConfPrmMTempCollection),man);
gv_Answers.DataBind();
man.Clear();
}
}
And this code is for setting the datasource of the detail grid:
protected void
gv_ParameterTempD_BeforePerformDataSelect(object
sender, EventArgs e)
{
ASPxGridView detailGrid = sender as ASPxGridView;
masterKey = detailGrid.GetMasterRowKeyValue().ToString();
man.Add(new SqlOperatorEquality("MAND_CONF_PRM_D_TEMP.PARAMETER_M_TEMP_ID", Convert.ToInt32(masterKey)));
detailGrid.DataSource = gc.LoadCollectionFromCollType(typeof(ConfPrmDTempCollection),man);
}
I see that you set the master grid's DataSource in the CustomCallback event handler. Try to cache the masterKey value in a Session variable and set the grid's DataSource not only in the CustomCallback event handler but also in the Page_Init method:
protected void Page_Init(object sender, EventArgs e) {
if(Session["masterKey"] == null)
return;
ConfPrmMTempCollection _ConfPrmMTempCollection = new ConfPrmMTempCollection();
masterKey = Session["masterKey"].ToString();
if (masterKey != "")
{
man.Add(new SqlOperatorEquality("MAND_CONF_PRM_M_TEMP.PARAMETER_M_TEMP_ID", Convert.ToInt32(masterKey)));
gv_Answers.DataSource = gc.LoadCollectionFromCollType(typeof(ConfPrmMTempCollection),man);
man.Clear();
}
}
protected void Page_Load(object sender, EventArgs e) {
gv_Answers.DataBind();
}
Does this help?
I have created a sample project based on your description and it works fine. It is available to download from:
http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=Q220495

ASP DetailsView, conditionally hide show controls and row?

I conditionally hide/show panels in a DetailsView...
I want to also hide/show the DetailsView row/field that the panel is contained in
because it is currently displaying empty rows when the panels are hidden?
ASCX:
<asp:DetailsView>
<asp:TemplateField>
<ItemTemplate>
<asp:panel runat="server" ID="pnlHideShow" OnInit="OnInit_Panel">
...
CodeBehind:
protected void OnInit_Panel(object sender, EventArgs e)
{
Panel pnl = (Panel) sender;
pnl.Visible = false;
switch (pnl.ID)
{
default:
break;
case "pnlHideShow":
pnl.Visible = (some condition);
//How to hide/show DetailsView item containing this panel?
break;
...
}
...
}
Hope I am not a candidate for "worse-than-failure" ;)
Something like:
pnl.Visible = (some condition);
pnl.Parent.Visible = true; // you may have to go pnl.Parent.Parent.Parent.Visible... try stepping through debug

Resources