Pass Parameter to LinqDataSource "OnSelecting" for Stored Procedure - linqdatasource

I'm building a semi-elaborate RadGrid where within my NestedViewTemplate I want to have a LinqDataSource that uses a Stored Procedure to get data from the database.
Here's what I have so far
<asp:HiddenField runat="server" ID="HiddenID" Value='<%#DataBinder.Eval(Container.DataItem, "ID")%>' />
<asp:LinqDataSource ID="LinqDataSource1" runat="server" OnSelecting="LinqDataSource_Selecting">
<WhereParameters>
<asp:ControlParameter ControlID="HiddenID" PropertyName="ID" Type="String" Name="ID" />
</WhereParameters>
</asp:LinqDataSource>
any my Code Behind...
Protected Sub LinqDataSource_Selecting(ByVal sender As Object, ByVal e As LinqDataSourceSelectEventArgs)
Dim hdc As New DAL.HealthMonitorDataContext()
e.Result = hdc.bt_HealthMonitor_GetByID(Integer.Parse(e.WhereParameters("ID")))
End Sub
but unfortunately hdc.bt_HealthMonitor_GetByID(Integer.Parse(e.WhereParameters("ID"))) isn't playing nice...
Exception Details:
System.FormatException: Input string was not in a correct format.

The "PropertyName" was incorrect in the WhereParameters.
<asp:ControlParameter ControlID="HiddenID"
PropertyName="Value"
Type="String"
Name="ID" />

Related

Callback error: Specific cast is not valid

I'm using a devexpress editform on my visual basic project. I ask for user input on a ASPxGridView, one of the values is called, Start Date which is declare on the grid as:
<dx:GridViewDataDateColumn Caption="Start Date" FieldName="StartDate" HeaderStyle-Wrap="true" UnboundType="String" EditFormSettings-VisibleIndex="1" >
<PropertiesDateEdit DisplayFormatString="D" EditFormatString="D" ValidationSettings-RequiredField-IsRequired ="true"></PropertiesDateEdit>
</dx:GridViewDataDateColumn>
And the datasource looks like this:
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SpEdPortalConnectionString %>"
SelectCommand="ProcedureName" SelectCommandType="StoredProcedure"
UpdateCommand="ProcedureName" UpdateCommandType="StoredProcedure"
InsertCommand="ProcedureName" InsertCommandType="StoredProcedure">
<SelectParameters>
***
</SelectParameters>
<UpdateParameters>
***
</UpdateParameters>
<InsertParameters>
***
<asp:Parameter Name="StartDate" Type="String" />
***
</InsertParameters>
</asp:SqlDataSource>
Problem: Even if I actually select a datevalue for the StartDate the value inserted on the DB is null.
Note:The callback error only shows on the deployed server not on local environment.But on local it inserts null so seems like the problem is there too but is not throwing an exeption.
I could not find the cause but the problem was solve by adding an EditTemplate tag and manually binding the value as follows:
<dx:GridViewDataDateColumn Caption="Start Date" FieldName="StartDate" HeaderStyle-Wrap="true" UnboundType="String" EditFormSettings-VisibleIndex="1" >
<PropertiesDateEdit DisplayFormatString="D" EditFormatString="D" ValidationSettings-RequiredField-IsRequired ="true"></PropertiesDateEdit>
<EditItemTemplate>
<dx:ASPxDateEdit ID="dteSD" runat="server" ClientInstanceName="dteSD"
Date='<%# Bind("StartDate") %>'>
</dx:ASPxDateEdit>
</EditItemTemplate>
</dx:GridViewDataDateColumn>
If the format changes you can just add Theme property inside the dx:ASPxDateEdit tag

Set <chart:guide> value at runtime

I'm trying to access the
<chart:guide>
value property from the screen controller, but I can't find any getter to reach it. The xml block is like this:
<chart:valueAxes>
<chart:axis position="LEFT"
stackType="REGULAR"
title="Graph Title">
<chart:guides>
<chart:guide
value="0"
inside="true"
lineAlpha="1"
/>
</chart:guides>
</chart:axis>
</chart:valueAxes>
I need to set the value of the guide at runtime. Any suggestion?
Let's say we have the following SerialChart:
<chart:serialChart id="serialChart"
caption="Serial chart"
height="100%"
width="100%"
categoryField="x">
<chart:graphs>
<chart:graph valueField="y"/>
</chart:graphs>
<chart:valueAxes>
<chart:axis position="LEFT">
<chart:guides>
<chart:guide value="12"
inside="true"
lineAlpha="1"/>
</chart:guides>
</chart:axis>
</chart:valueAxes>
<chart:data>
<chart:item>
<chart:property name="x" value="10"/>
<chart:property name="y" value="12"/>
</chart:item>
<chart:item>
<chart:property name="x" value="11"/>
<chart:property name="y" value="2"/>
</chart:item>
<chart:item>
<chart:property name="x" value="12"/>
<chart:property name="y" value="120"/>
</chart:item>
<chart:item>
<chart:property name="x" value="13"/>
<chart:property name="y" value="16"/>
</chart:item>
</chart:data>
</chart:serialChart>
You can simply get ValueAxis and then get Guide object by index or iterate collection and find by id (optional attribute of Guide):
#Inject
private SerialChart serialChart;
ValueAxis valueAxis = serialChart.getValueAxes().get(0);
Guide guide = valueAxis.getGuides().get(0);
guide.setValue(15);
serialChart.repaint();
Note, if we want to change already displayed chart configuration then we have to call repaint() method.
If you use CUBA 6.4 or older, you have to obtain Configuration object first using getConfiguration() method and cast it to appropriate chart type as shown here: https://doc.cuba-platform.com/charts-6.4/cdp_screen_controller.html

How to pass the querystring parameter into FormControl in vb.net

I am passing a value from one form to the other. The second form in inserting the data field into the table. How do I pass the ID(strPID) passed from the first form into the form control PatronIDTextBox of the second form?
VB.Code: on Page load -- strPID = Request.QueryString("value1")
Form control:
<InsertItemTemplate>
PatronID:
<asp:TextBox ID="PatronIDTextBox" runat="server" Text='<%# Bind("PatronID") %>' />
Thanks
Ok, Now I am trying to say it this way in object datasource so I can send it into insert statement without being displayed on the screen.
<Insert Parameters>
<asp:QueryStringParameter Name="PatronID" Type="int32" QueryStringField="value1" />
<asp:QueryStringParameter Name="PatronName" Type="String" QueryStringField="value2" />
</InsertParameter>
InsertCommand="INSERT INTO [tblIncident] ([PatronID], [PatronName]) values (#PatronID, #PatronName)
Have you tried directly putting the value into the textbox? Like this:
<asp:TextBox ID="PatronIDTextBox" runat="server" Text='<%= Request.QueryString("Value1") %>' />
Just be careful, because this approach could allow a XSS attack. You might want to read-up on those.
I deleted the text box for both id and name and instead I modified the objectdatasource Insert statement as follows. The value of value1 and value2 is captured on page load event.
<InsertParameters>
<asp:QueryStringParameter Name="PatronID" Type="Int32" QueryStringField="value1" />
<asp:QueryStringParameter Name="PatronName" Type="String" QueryStringField="value2"/>
</InsertParameters>

ASPxGridView GetSelectedFieldValues not retrieving values

I'm trying to make such a simple thing as getting one value from the selected row in an ASPxGridView with the GetSelectedFieldValues method with a button.
I've followed the steps from DevExpress documentation with the difference I want to retrieve the value inside a Label. Nothing difficult with classic ASPGridView.
Protected Sub ASPxButton1_Click(sender As Object, e As EventArgs) Handles ASPxButton1.Click
Dim oRowVal As List(Of Object)
Dim oVal As Object
oRowVal = ASPxGridView1.GetSelectedFieldValues({"No_"})
oVal = oRowVal(0)
Label1.Text = oVal.ToString
End Sub
As you can see, the thing I want is to get the selected value within the ASPxGridView and display it in a Label.
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="ASPxButton" Theme="BlackGlass" Width="150px">
</dx:ASPxButton>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EnableTheming="True" Theme="BlackGlass">
<Columns>
<dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
<ClearFilterButton Visible="True">
</ClearFilterButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn Caption="GP" FieldName="No_" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Description" FieldName="DescripciĆ³n Grupo" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<SettingsBehavior AllowSelectSingleRowOnly="True" />
<Settings ShowFilterRow="True" ShowGroupPanel="True" />
</dx:ASPxGridView>
Thanks in advance!!!
Specify the ASPxGridView.KeyFieldName property in order to use the Selection state:
<dx:ASPxGridView ... KeyFieldName="...">
By the way, does the following code return the correct results?
oRowVal = ASPxGridView1.GetSelectedFieldValues({"No_"})
oVal = oRowVal(0)

how to retrieve binary image from database in vb.net and insert the image in grid view

How to retrieve a binary image from a database using vb.net and insert the image into a GridView.
This is my DB
image (id as integer , img as varbinary(max))
While you clarify the type of gridview you are referring to, here's how to insert the data in the database:
Using c As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
c.Open()
Dim command = New SqlCommand("INSERT INTO yourtable(image) values (#image)", c)
' this is specific to the FileUploadControl but the idea is to get the
'image in a byte array; however you do it, it doesn't matter
Dim buffer(FileUpload1.PostedFile.ContentLength) As Byte
FileUpload1.PostedFile.InputStream.Read(buffer, 0, buffer.Length)
command.Parameters.AddWithValue("#image", buffer)
command.ExecuteNonQuery()
End Using
And assuming you are talking about an ASP .NET app, you can bind the data to the gridview as follows:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<!--Trick to encode the bytes as a BASE64 string-->
<img width="100px" height="100px" src='data:image/png;base64,<%#System.Convert.ToBase64String(Eval("image"))%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=Your_ConnectionString_GoesHere"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [id], [image] FROM [your_table_name_goes_here]">
</asp:SqlDataSource>