In linq how to work on Storprocedure - asp.net

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.

Related

Unable to get selected item of dx:ASPxListBox on ASPxGridView_Updating event of devexpress control

I have used dx:ASPxGridView where I have one dx:GridViewDataTextColumn with EditItemTemplate which contain dx:ASPxListBox. When I click on update command I am not able to get selected items of dx:ASPxListBox under ASPxGridView_Updating.
<dx:ASPxGridView
ID="ASPxGridView"
runat="server"
AutoGenerateColumns="False"
DataSourceID="TradersDS"
KeyFieldName="TraderId">
<SettingsEditing Mode="PopupEditForm" PopupEditFormWidth="600px" />
<ClientSideEvents RowDblClick="function(s, e)
{
s.StartEditRow(e.visibleIndex);
}"
EndCallback="PrepareGridViewForNewDesing" Init="PrepareGridViewForNewDesing" />
<Columns>
....
<dx:GridViewDataTextColumn FieldName="CounterParty" VisibleIndex="3">
<EditItemTemplate>
<dx:ASPxListBox ID="lstCounterParty" runat="server" SelectionMode="CheckColumn" EnableSelectAll="true"
Width="285"
Height="300"
DataSourceID="CounterPartiesDS"
ValueField="ID"
ValueType="System.String"
TextField="Name">
<%-- <ClientSideEvents SelectedIndexChanged="function(s, e) {lbModels.PerformCallback('1');}" />--%>
</dx:ASPxListBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
...
</Columns>
</dx:ASPxGridView>
C# Code..
protected override void ASPxGridView_Updating(object sender, ASPxDataUpdatingEventArgs e)
{
var gridView = sender as ASPxGridView;
GridViewDataColumn list = gridView.Columns["CounterParty"] as GridViewDataColumn;
var counterPartyListBox = (ASPxListBox)gridView.FindEditRowCellTemplateControl(list, "lstCounterParty");
string selectedItemsAsString = string.Empty;
foreach (ListEditItem item in counterPartyListBox.SelectedItems)
selectedItemsAsString += item.Value + ";";
base.ASPxGridView_Updating(sender, e);
}
Here I always get count 0 of SelectedItems. On addition to this My devExpress control version are 9.3.3
What is wrong with this code any help , guidance really appreciated.
Make sure that you set the ASPxListBox.ValueType property to the corresponding .NET type that matches the type of the "ValueField" column.
May be, according to the (ValueField="ID"), the (ASPxListBox.ValueType) should be numeric? (System.Int32, etc.)

how to write trigger combobox events which is present inside aspxgridview

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);
}
}" />

Is InsertMethod broken when using ASPxGridView and ObjectDatasource with a custom EditForm?

I have an ASPxGridView, currently 11.1.7.0, which I populate with an ObjectDatasource. Everything works as expected until I use a custom editform. In another control i solved this by using the OnRowInserting attribute in the aspxgridview control, but I dont like this since it's extra work compared to using the objectdatasource.
The code looks something like this.
<dx:ASPxGridView ID="ASPxGridView1" runat="server"
ClientIDMode="AutoID"
AutoGenerateColumns="False"
KeyFieldName="UserId"
DataSourceID="ObjectDataSource1"
ClientInstanceName="grid"
onhtmleditformcreated="AsPxGridView1HtmlEditFormCreated">
<SettingsEditing PopupEditFormWidth="600" PopupEditFormModal="true" Mode="EditForm" />
<Templates>
<TitlePanel>
<dx:ASPxButton ID="New" runat="server" Text="Ny användare" ClientInstanceName="New" AutoPostBack="false">
<ClientSideEvents Click="function (s, e) { grid.AddNewRow(); }" />
</dx:ASPxButton>
</TitlePanel>
<EditForm>
First Name: <dx:ASPxTextBox ID="FirstName" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server" />
</EditForm>
</Templates>
<Columns>
<dx:GridViewDataTextColumn FieldName="UserId" VisibleIndex="0" />
<dx:GridViewDataTextColumn FieldName="FirstName" VisibleIndex="2" />
<dx:GridViewDataTextColumn FieldName="LastName" VisibleIndex="3" />
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource
ID="ObjectDataSource1"
TypeName="UserData"
SelectMethod="GetItems"
UpdateMethod="ItemUpdate"
InsertMethod="ItemInsert"
DeleteMethod="ItemDelete"
runat="server">
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String"/>
</InsertParameters>
</asp:ObjectDataSource>
And the UserData object
public class UserData
{
public List<TblProUserData> GetItems()
{
var tblProUserData = new TblProUserData();
tblProUserData.Fill();
return tblProUserData.List;
}
public void ItemDelete(int userId)
{ }
public void ItemUpdate()
{ }
public void ItemInsert(string FirstName)
{
// This method gets called, but the FirstName is null.
}
}
The problem is that the ItemInsert gets called, but the FirstName attribute is always null.
Is this a bug? is there a way around this? Did I miss something?
Thanks.
It is necessary to use the Two-Way data-binding technique to bind template editors with DataItem's fields:
<dx:ASPxTextBox ID="FirstName" runat="server" Text='<%#Bind("FirstName")%>' />
Based off the following question, specifying TypeName="UserData" could be causing the problem.
ObjectDataSource not calling Insert method when it has extra parameters
Try removing that from the asp:ObjectDataSource and see if the ItemInsert method works.

How to find control nested into ASPXGridview on button click

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.

ASPxGridView and LinqServerModeDataSource, inserting rows by stored procedure

I have a page using ASPxGridView and to fill the GridView I use a LinqServerModeDataSource control who fetches it data through a SQL View from a MS SQL Server. So far so good but here comes the problem.
I want to insert data in the database so I'm building a custom form
<Templates>
<EditForm>
Company Name: <dx:ASPxTextBox ID="CompanyName" runat="server" />
Company Mail: <dx:ASPxTextBox ID="Email" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server" />
</EditForm>
</Templates>
Here is an example of the custom form
Pretty basic stuff, in this scenario the Company name goes to one table and the email to another. This is all handled by calling a Stored Procedure. Or thats the plan.
Does anyone know how to do this?
It feels like I've been trying it all, LinqServerModeDataSource1_Inserting, ASPxGridView1_RowInserting and so on but nooo. Here is one of the failing codes. And the devexpress documentation is even worse, but lets not go there its not a happy place.
protected void LinqServerModeDataSource1_Inserting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceEditEventArgs e)
{
// Some magic to insert data here
ASPxGridView1.CancelEdit();
}
So, any advice or help is highly appreciated.
Thanks!
"I want to insert data in the database so I'm building a custom form" ASPxGridView can do all that for you without you having to make a custom template at least with sqldb
If i would define a delete command and or edit command below to the sqldatasource i could already delete and edit the information in the gridview
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
ClientIDMode="AutoID" DataSourceID="SqlDataSource1">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
<NewButton Visible="True">
</NewButton>
<DeleteButton Visible="True">
</DeleteButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="Naam" VisibleIndex="0">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Adres" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Postcode" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Plaats" VisibleIndex="3">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Name], [Address], [Postcode], [City] FROM [Somewhere]">
</asp:SqlDataSource>
But you can if you really want to use a custom made insert or delete
protected void ASPxGridView4_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
DataColumn[] esl = new DataColumn[] { dt.Columns["SQLWaarde"] };
if (ds.Tables[0].PrimaryKey == null || ds.Tables[0].PrimaryKey == esl)
{
ds.Tables[0].PrimaryKey = new DataColumn[] { dt.Columns["SQLWaarde"] };
}
DataRow[] delRow = ds2.Tables[0].Select("IndWaardeType = '" + e.Values[1] + "' AND SQLWaarde = '" + e.Values[2] + "'");
ds2.Tables[0].Rows.Remove(delRow[0] as DataRow);
e.Cancel = true;
ASPxGridView4.CancelEdit();
Session["ds2"] = ds2;
}
protected void ASPxGridView4_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
ndr2 = ds2.Tables[0].NewRow();
ndr2[0] = e.NewValues[0];
ndr2[1] = e.NewValues[1];
ndr2[2] = e.NewValues[2];
ds2.Tables[0].Rows.Add(ndr2);
e.Cancel = true;
ASPxGridView4.CancelEdit();
Session["ds2"] = ds2;
}
That's how i did it last time. I made use of datatables and stored that in sessions bla bla realy just trying out but it works alright.

Resources