JQ Grid Compilation Error - jqgrid-asp.net

I am new to JQGrid.I downloaded Jqgrid and added the dll in the project.I added a sql data source.but it is showing an error.
Error: 'Trirand.Web.UI.WebControls.JQGridColumn.SearchDataType' is obsolete: 'SearchDataType is now obsolete. Use DataType instead. At runtime set as JQGridColumn.DataType = typeof(string).'
The code after adding sql datasource is
<cc1:JQGrid ID="JQGrid1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<cc1:JQGridColumn DataField="studentid" PrimaryKey="True"
SearchDataType="NotSet">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="studentname" SearchDataType="NotSet">
</cc1:JQGridColumn>
<cc1:JQGridColumn DataField="schoolname" SearchDataType="NotSet">
</cc1:JQGridColumn>
</Columns>
</cc1:JQGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:EffortConnectionString1 %>"
SelectCommand="SELECT [studentid], [studentname], [schoolname] FROM [testjqgrid]">
</asp:SqlDataSource>
Please help me???

Related

GridView hyperlink for Date field is not displaying using vb.net

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="637px" CssClass="auto-style1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="TimeStamp" DataNavigateUrlFormatString="Logs.aspx?TimeStamp={0}" DataTextField="TimeStamp" HeaderText="TIME STAMP"></asp:HyperLinkField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SoneilCloudRemConnectionString %>"
SelectCommand="SELECT [TimeStamp] FROM [SensorLogData] WHERE ([deviceId] = #deviceId)">
<SelectParameters>
<asp:Parameter DefaultValue="121313131" Name="deviceId" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
The above is the code snippet used for displaying date with hyperlink. For me it displays just the date instead of it to be hyperlink. In my SQL the datatype for this date is in "datetime" format.
I tried using other field to display in hyperlink, it's working. Finding issue only for datetime.
The Gridview won't build a URL containing : (which is in the time portion of Timestamp). This results in an <a> tag being created with no href.
If you can live without the time, you can change the DataNavigateUrlFormatString to only use the date portion:
DataNavigateUrlFormatString="Logs.aspx?TimeStamp={0:d}"
Another option is described here. It would involve formatting Timestamp to a specific format & then parsing the querystring Timestamp using `DateTime.ParseExact().
DataNavigateUrlFormatString="Logs.aspx?TimeStamp={0:yyyy-MM-dd hh-mm-ss}"
Then on Logs.aspx:
DateTime.ParseExact(Request.QueryString("Timestamp").ToString(), "yyyy-MM-dd hh-mm-ss", System.Globalization.CultureInfo.CurrentCulture)

Using a different value from a drop down list

Sorry my title is crap but cant think of a better way to put it.
Using MS VS 2013 and MS SQL server 2012. VB
I have a drop down list and the stored procedure it calls gets two values from a table in SQL. The values are the ID and the name. The drop down list is displaying the name but I want to use the ID when a name is selected in the drop down list in code.
How do I do this?
My code for the DDL is
<asp:DropDownList ID="DDLAllTreatments" runat="server" DataSourceID="AllTreatments" DataTextField="Name" DataValueField="Name"></asp:DropDownList>
<asp:SqlDataSource ID="AllTreatments" runat="server" ConnectionString="<%$ ConnectionStrings:InfinitySPa %>" SelectCommand="SP_GetAllTreatments" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
Change DataValueField to ID:
<asp:DropDownList ID="DDLAllTreatments" runat="server" DataSourceID="AllTreatments" DataTextField="Name" DataValueField="ID"></asp:DropDownList>
<asp:SqlDataSource ID="AllTreatments" runat="server" ConnectionString="<%$ ConnectionStrings:InfinitySPa %>" SelectCommand="SP_GetAllTreatments" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

How can I bind a gridview to datasource with dynamic WHERE clause?

I am using Visual Basic for ASP. NET
I know how to populate a gridview with data using only code behind, like this
Dim ds as new datasourse
Dim da as new dataadaptor
Dim con as new SqlConnection
Dim cmd as new SqlCommand
...
Cmd = "select ticketID, problem_text from problems where support_engineer = " & Session("Logged_in_user_id")
...
Gridview1.Datasource = ds
Gridview1.Datasources. DataBind
And that works fines, but my question is: how can i drag and drop a gridview control, and using only the wizard to populate the gridview in design time, how can i define the SELECT statement to only select rows that are related to the logged in user id? See the sql statement above, it uses a session variable that i create in Page_Load event, but how can i use the same logic in design mode? (i don't want to modify the datasource control in code behind)
I looked in youtube and google, and this sites, but all results are simply showing me how to populate the gridview with all rows or with a static condition, not a dynamic one like the one i demonestrated.
Any help is highly appreciated
You could try replacing the form tag in the aspx file
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="SELECT ticketID, problem_text FROM Tabs WHERE (support_engineer = #Param1)">
<SelectParameters>
<asp:SessionParameter Name="Param1" SessionField="Logged_in_user_id" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True"
DataSourceID="SqlDataSource1">
</asp:GridView>
</div>
</form>
I found out the proper way of binding the gridview to a dynamic session variable, without involving code behind:. Simply use the property <SessionParameter> inside the <SelectParameter>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="SELECT ticketID, problem_text FROM problems
WHERE (support_engineer = #eng_id)
<SelectParameters>
<asp:SessionParameter
Name="eng_id"
SessionField="LoggedInUser"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True"
DataSourceID="SqlDataSource1">
</asp:GridView>

change text on a hyperlink in a datalist

I'm trying to bind a column from a SQL code that i have written to all hyperlinks in a datalist. This should be really simple but I'm getting the error
DataBinding: 'System.Data.Common.DataRecordInternal' does not contain
a property with the name 'NumberOfComments'.
Well I'm pretty sure the column exist but in this case it's created by a function maybe that has something to do with it. When I run the SQL code i get the values I should.
The hyperlink
<asp:HyperLink ID="lnkComment" runat="server"
NavigateUrl='<%# Eval("ID", "~/Default.aspx?ID={0}") %>'
Text='<%# Eval("NumberOfComments") %>'></asp:HyperLink>
The SQLDataSource
<asp:SqlDataSource ID="sdsNews" runat="server"
ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>" SelectCommand="SELECT News.ID, News.Topic, News.Text, News.PostTime, aspnet_Users.UserName, "NumberOfComments" = dbo.fnNumberOfCommentOnNews(News.ID)
FROM News INNER JOIN
aspnet_Users ON News.UserId = aspnet_Users.UserId
WHERE (News.ID = ISNULL(#ID, News.ID))
ORDER BY News.PostTime DESC ">
<SelectParameters>
<asp:QueryStringParameter DbType="Guid" Name="ID" QueryStringField="ID" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
Why do you have """ surrounding NumberOfComments FieldName?
Try pasting the select command into SSMS (SQL Server Mgmt studio) and you should most definitely get an incorrect syntax error. If you drop those quot html code you will still be able to reference and bind to that column.

Using SelectParameters in ASP.NET gives 'Must declare variable' errors

I have an ASP SqlDataSource connected to Sybase DB query, using Select Parameters that are populated by a dropdown:
Dropdown (works OK):
<asp:SqlDataSource ID="dsBondIDList" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [name], [bondID] FROM [bonds]">
</asp:SqlDataSource>
<asp:DropDownList ID="lstBondID" runat="server" DataSourceID="dsBondIDList" DataTextField="name" DataValueField="bondID">
SqlDataSource with parameter:
<asp:SqlDataSource ID="dsBonds" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [ticker], [name], [isin], [currency],
[stock], [maturity], [bid], [ask]
FROM [bonds] where [bondID] = #bondID">
<SelectParameters>
<asp:ControlParameter Name="bondID" ControlID="lstBondID" PropertyName="SelectedValue" DefaultValue="-1" />
</SelectParameters>
</asp:SqlDataSource>
But I get an error when I try to run it:
ERROR [HY000] [DataDirect][ODBC Sybase Wire Protocol driver][SQL Server]Must declare variable '#bondID'.
Which of course I would get it I ran the sql literally as displayed. I expect the ASP engine to do the substitution before sending the query (and to use the default value of lstBondID if necessary)
Does anybody know why the #bondID is not being substituted with the lstBondID.SelectedValue?
Thanks in advance
Ryan
I just went through this problem 10 minutes ago and here's the fix:
If you need to keep using the ODBC driver you have, change your query to use ? instead of Named Parameters.
SELECT [ticker], [name], [isin], [currency],
[stock], [maturity], [bid], [ask]
FROM [bonds] where [bondID] = ?
The parameters are used in the order they are added to the parameters collection (This gets hairy when you need to use the parameter more than once in your query etc).
Otherwise you can change drivers. Look for sybdrvodb.dll and regsvr32 it. Then setup your DSN and use that.

Resources