I am using devexpress asp:GridView in asp.net with two columns: "status" and "percentage"
The column "status" is a GridViewDataComboBoxColumn which contain two values: "progress" and "completed"
The column "percentage" is a GridViewDataColumn.
What I want to do is:
If I select completed in status then the percentage should display the text '100'.
but I don't know how to trigger combobox events which is present inside asp:GridView
The code I have (so far) is:
<dxwgv:ASPxGridView ID="gridviewTaskProg" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSourceTasks"
onbeforeperformdataselect="gridviewTaskProg_BeforePerformDataSelect"
onrowupdating="gridviewTaskProg_RowUpdating" KeyFieldName="intProgressID"
oninitnewrow="gridviewTaskProg_InitNewRow"
onrowinserting="gridviewTaskProg_RowInserting"
oncancelrowediting="gridviewTaskProg_CancelRowEditing"
onstartrowediting="gridviewTaskProg_StartRowEditing">
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataDateColumn FieldName="StartDateTime" VisibleIndex="1">
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt"
EditFormat="Custom" EditFormatString="dd/MM/yyyy hh:mm tt"></PropertiesDateEdit>
</dxwgv:GridViewDataDateColumn>
<dxwgv:GridViewDataDateColumn FieldName="EndDateTime" VisibleIndex="2">
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt"
EditFormat="Custom" EditFormatString="dd/MM/yyyy hh:mm tt"
dateonerror="Today"></PropertiesDateEdit>
</dxwgv:GridViewDataDateColumn>
<dxwgv:GridViewDataSpinEditColumn FieldName="Percentage" VisibleIndex="3">
<PropertiesSpinEdit DisplayFormatString="g" NumberFormat="Custom"></PropertiesSpinEdit>
</dxwgv:GridViewDataSpinEditColumn>
<dxwgv:GridViewDataComboBoxColumn FieldName="Status" VisibleIndex="4">
<PropertiesComboBox ValueType="System.String"><Items><dxe:ListEditItem Text="Progress" Value="Progress" /><dxe:ListEditItem Text="Completed" Value="Completed"/></Items></PropertiesComboBox>
</dxwgv:GridViewDataComboBoxColumn>
<dxwgv:GridViewDataMemoColumn Caption="Remarks" FieldName="Remarks"
VisibleIndex="5">
</dxwgv:GridViewDataMemoColumn>
</Columns>
</dxwgv:ASPxGridView>
Set grid ClientInstanceName to "grid1" (or any other name, just replace it in my code). Change status combo box column as follows:
<dxwgv:GridViewDataComboBoxColumn FieldName="Status" VisibleIndex="4">
<PropertiesComboBox ValueType="System.String">
<Items>
<dxe:ListEditItem Text="Progress" Value="Progress" />
<dxe:ListEditItem Text="Completed" Value="Completed"/>
</Items>
<ClientSideEvents
SelectedIndexChanged="function(s,e) {
if(s.GetValue()=='Completed')
grid1.GetEditor('Percentage').SetValue(100);
}"
/>
</PropertiesComboBox>
</dxwgv:GridViewDataComboBoxColumn>
How can i change the readonly property of 'percentage'?
#Filip: Exactly!
<ClientSideEvents SelectedIndexChanged="function(s, e) {
if(s.GetValue() == 'Completed') {
var txtEditor = grid1.GetEditor('Percentage');
txtEditor.SetValue(100);
txtEditor.SetEnabled(false);
}
}" />
Related
<dx:GridViewDataDateColumn FieldName="ScheduledTimeForDelivery" Caption="Scheduled Time For Delivery" Width="14%" VisibleIndex="5">
<Settings AutoFilterCondition="Contains" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="True" Wrap="True" />
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt" EditFormatString="dd/MM/yyyy hh:mm tt">
<TimeSectionProperties Visible="true">
<TimeEditProperties EditFormatString="hh:mm tt" EditFormat="Custom"></TimeEditProperties>
</TimeSectionProperties>
<ValidationSettings RequiredField-IsRequired="true" ErrorTextPosition="Bottom" ErrorDisplayMode="Text">
<RequiredField ErrorText="Please enter the Scheduled Time For Delivery" />
</ValidationSettings>
</PropertiesDateEdit>
<EditFormSettings VisibleIndex="3" />
</dx:GridViewDataDateColumn>
I want to disable all previous dates in my Column"ScheduledTimeForDelivery" how to disable it previous dates.
Reference: ASPxGridview - date column
Use the editor's MaxDate and MinDate properties for this purpose. For example:
GridViewDataDateColumn dateColumn = gridView.Columns["ScheduledTimeForDelivery"] as GridViewDataDateColumn;
dateColumn.PropertiesDateEdit.MaxDate = System.DateTime.Now.AddYears(5);
dateColumn.PropertiesDateEdit.MinDate = System.DateTime.Now.AddYears(-5);
Or you can manage to do it in aspx page also with help of documentation..
Disabling specific dates in ASPxDateEdit, in Edit form of ASPxGridView
Hope this help..
use this line in cell editor initialize even
if (e.Column.FieldName == "ScheduledTimeForDelivery")
(e.Editor as ASPxDateEdit).MinDate = DateTime.Now.Date;
I have a grid like below.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" s
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:ButtonField DataTextField="Name" HeaderText="Name" />
<asp:BoundField DataField="ArrDate" DataFormatString="{0:MM/dd/yyyy}"
HeaderText="Arr Date" />
<asp:BoundField HeaderText="Dep Date" DataField="DepDate"
DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField HeaderText="Mail" DataField="Mail" />
<asp:BoundField HeaderText="Status" DataField="Status" />
<asp:BoundField DataField="ResId" HeaderText="ResId" Visible="False" />
</Columns>
</asp:GridView>
In Code Behind:-
try
{
string text = GridView1.Rows[2].Cells[5].Text;
ScriptManager.RegisterStartupScript(this, GetType(), "Message", "alert('ResId = " + text + ".');", true);
}
catch { }
Now the message shows - RegId =.
I can't get the value. So I change the RedId BoundField as vissible. Now I got the Value.
that is RegId =6.
I have two issue now -
1) How to get the RegId value in Non Visible Column.
2) How I find the Row value which i click... bzs the only i can change the ROWVALUE in code..
string text = GridView1.Rows[ROWVALUE].Cells[5].Text;
That is certainly not the right way to do it. You might want to look at using DataKeys to achieve this. With current approach, when you add a new column to your grid your code will fail.
Add your RegId column inside DataKeys property on your gridview
Reference your gridview datakey for the current row in codebehind like this
int regId= Convert.ToInt32(YourGridview.DataKeys[rowIndex]["RegId"].ToString());
I am displaying my data in a devexpress gridview. One of the column is state value. When the grid is edited, I have to show the state in a combobox, so that the user could change the state by choosing a different state. Currently it is displayed in a textbox, since it is the default. Essentially when the user clicks the edit button, a combobox should be displayed as part of the edit controls, and the combobox should be populated with all possible states in the codebehind and the selected value should be the initial value on the grid. It is very easy do it in MS gridview. But I couldn't see any sample code for how to do it in the devexpress gridview.
Thanks
Use GridViewDataComboBoxColumn. Declare datasource and attach it to combo box column or populate it in code behind. This example contains both variants.
You can also take a look at DevExpress grid editing demos.
<dx:GridViewDataTextColumn FieldName="FieldName" VisibleIndex="4">
<EditItemTemplate>
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" DataSourceID="newDataSource" >
</dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
You'll need to set the datasource so you'll get the list of values
If you don't have a data source and want to include the combo box items in your code, here's another way to create the column:
<dx:GridViewDataComboBoxColumn FieldName="QAAproval" VisibleIndex="11" Width="30px">
<PropertiesComboBox>`enter code here`
<Items>
<dx:ListEditItem Text="GENERIC" Value="GENERIC" />
<dx:ListEditItem Text="FAIR" Value="FAIR" />
<dx:ListEditItem Text="VSE" Value="VSE" />
<dx:ListEditItem Text="ECAV" Value="ECAV" />
<dx:ListEditItem Text="FMMDS" Value="FMMDS" />
<dx:ListEditItem Text="CLEAR" Value="CLEAR" />
</Items>
</PropertiesComboBox>
<CellStyle Font-Size="XX-Small">
</CellStyle>
</dx:GridViewDataComboBoxColumn>
Edit the GridView Template, and in the EditTemplate of the field, add the dropdownbox. It might come to look like this
<dx:GridViewDataTextColumn Caption="Field Name"
FieldName="FieldName" VisibleIndex="3">
<EditItemTemplate>
<cc1:DropDownList ID="DropDownList1" runat="server">
</cc1:DropDownList>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
So when you edit that row, it will show the DDL
I have used the following code to have combo box in the aspxgridview.
I hope this example helps :
<dx:GridViewDataComboBoxColumn FieldName="DatabaseFieldName" Settings-FilterMode="DisplayText"
Width="3%" VisibleIndex="3" Visible="True" Caption="Priority" Settings-AutoFilterCondition="Contains"
HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Center"
CellStyle-VerticalAlign="Top">
<PropertiesComboBox ValueType="System.String" DataSourceID="objDataSourceID"
Width="200px" Height="25px" TextField="TextFieldName" ValueField="ValueFieldName"
IncrementalFilteringMode="StartsWith">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
I have a text box and button inside of my ASPXGridview, DetailRow view. So when it's expanded I need to type text and click button and on server side to get value from the textbox.
Here is my code. The problem is somewhere on postback I'm loosing text value. So text box is empty
protected void Button1_Click(object sender, EventArgs e)
{
ASPxGridView grid = EmailGridView;
for (int i = 0; i < grid.VisibleRowCount; i++)
{
var txtDescription = (ASPxMemo)grid.FindDetailRowTemplateControl(i, "txtDescription");
if(txtDescription != null)
{
var text = txtDescription.Text;
}
}
}
<dxwgv:ASPxGridView ID="EmailGridView" KeyFieldName="ThreadId" runat="server" AutoGenerateColumns="False"
OnHtmlRowCreated="EmailGridView_HtmlRowCreated" SettingsDetail-AllowOnlyOneMasterRowExpanded="true"
SettingsBehavior-ConfirmDelete="true" OnHtmlRowPrepared="EmailGridView_HtmlRowPrepared"
OnRowDeleted="EmailGridView_RowDeleted">
<SettingsBehavior ConfirmDelete="True" />
<Columns>
<dxwgv:GridViewDataTextColumn Caption="ID" FieldName="Id" VisibleIndex="0">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewCommandColumn VisibleIndex="5" Caption=" ">
<DeleteButton Visible="True">
</DeleteButton>
</dxwgv:GridViewCommandColumn>
</Columns>
<SettingsDetail ShowDetailRow="true" />
<SettingsBehavior ConfirmDelete="True" />
<SettingsDetail AllowOnlyOneMasterRowExpanded="True" ShowDetailRow="True" />
<Templates>
<DetailRow>
<dxwgv:ASPxGridView ID="EmailSubGridView" Width="750px" OnBeforePerformDataSelect="EmailSubGridView_BeforePerformDataSelect"
runat="server" AutoGenerateColumns="False"
onhtmlrowcreated="EmailSubGridView_HtmlRowCreated">
<Columns>
<dxwgv:GridViewDataTextColumn Caption="MessFrom" FieldName="MessFrom">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="Message" FieldName="Message">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="SendDtm" FieldName="SendDtm">
</dxwgv:GridViewDataTextColumn>
</Columns>
<StylesEditors>
<ProgressBar Height="25px">
</ProgressBar>
</StylesEditors>
</dxwgv:ASPxGridView>
<dx:ASPxMemo ID="txtDescription" runat="server" Width="170px" Height="71px"></dx:ASPxMemo>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Reply" />
</DetailRow>
</Templates>
Conny,
The ASPxGridView has callbacks built into it so I recommend using that approach as it's easier and it gives you a better user experience. The find method you're using requires the visiblerowindex.
Take a look a this code central example to see how to get data from the server:
How to bind the detail GridView to data based on the end-user input
If you want these process when you are expanding your ASPxGridview, you should use DetailRowExpandedChanged event.
This event works when you expand or collapse your ASPxGridview.
Mehul's example is very good actually for this situation. After that, if you still have a problem, you can ask your question in Devexpress Support. They are really helpful and quick.
I work on Northwind database.server MS2008.In linq i active a sp then show me the bellow error:
Syntax :
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="LinqServerModeDataSource1"
KeyFieldName="CategoryID">
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
<NewButton Visible="True">
</NewButton>
<DeleteButton Visible="True">
</DeleteButton>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataTextColumn Caption="CategoryID" FieldName="CategoryID"
VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="CategoryName" FieldName="CategoryName"
VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="Description" FieldName="Description"
VisibleIndex="3">
</dxwgv:GridViewDataTextColumn>
</Columns>
</dxwgv:ASPxGridView>
<dxdtlnq:LinqServerModeDataSource ID="LinqServerModeDataSource1" runat="server"
onselecting="LinqServerModeDataSource1_Selecting" />
C# syntax:
protected void LinqServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
{
NorthwindDataContext db=new NorthwindDataContext();
var r = db.SELECT_All_Product();
e.QueryableSource = r;
}
Error message:
Error 1 Cannot implicitly convert type 'System.Data.Linq.ISingleResult' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)
What to do solve this error.Why need custing.How to cust .Plz show some syntax
The reason is the fact that usually procedure returns an IEnumerable<TEntity> result.
You need a table-valued function to work with IQueryable<TEntity>. Take a look at this article for more information.