|
Sir, thank you so much for reply.
|
|
|
|
|
Hello,
Quick intro, My name is Jason and recently a work colleague retired and had developed several ASPX websites of which I have been tasked to support.
My previous background of programming is around Delphi, Intersystems Cache and more recently C# but these websites that I'm now supporting are all written in VB.net, asp.net, aspx or whatever language it is called, as you have probably guessed by now I have never used Visual Studio or produced code that created aspx files.
Anyway as a newbie to this language I have run into a problem that you experts will have learnt in school
I have a webpage (student.aspx) that contains this snippet of code :
<asp:DropDownList runat="server" ID="ddlCourse" DataTextField="Course"
DataValueField="Course" DataSourceID="SDSCourse"
Width="260px" onChange="CheckNerveCenter"/>
I have added the "onChange" bit
and this bit of code is also existing
<asp:CheckBox ID="chkNerveCentre" runat="server" Text="Nerve Centre" TextAlign="Left" />
So basically the page contains several combo boxes and several check boxes
I need to do some logic for 2 of them, code above.
If the combo box contains text (from database) with the word Nursing, Nurse, Nurses etc. lets say "*Nurs* then teh tick box needs to be disabled so it cannot be ticked
This is the code I have done in the code behind file student.aspx.vb, it just contains a comment now
Function CheckNerveCenter() As Object
'If ID="ddlCourse" contains any word like "*Nurs*" then
'uncheck ID="chkNerveCentre" and then disable ID="chkNerveCentre"
End Function
At first I tried to get it to display a message to show that it was calling the function from the "onChange" but it doesn't seem to work.
As I'm new to this language would you please just help a newbie in the right direction
I did try and use the OnChangeText in visual studio but it just kept showing me this error
"Property Value not valid","Error HRESULT E_FAIL has been returned from a call to a COM component." I have no idea what this means
That's why I decided to try and use a function of my own but now stuck
Any ideas please?
Jason
modified 7-Jul-22 7:31am.
|
|
|
|
|
The OnChange event will run on the server, when the page posts back to the server. That normally only happens when you click a button; if you want it to happen as soon as your list changes, you'll need to set the AutoPostBack property of the list to True .
ListControl.AutoPostBack Property (System.Web.UI.WebControls) | Microsoft Docs[^]
Your event handler method will need to match the expected signature:
Protected Sub CheckNerveCenter(ByVal sender As Object, ByVal e As EventArgs)
...
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
if you know than described the code
|
|
|
|
|
No, there isn't.
Your C# code will be running on the server. At best, you would capture a screenshot and system information of the server, which would not be much use.
The only code that runs on the client is your Javascript. And that has extremely limited access to the system it's running on, for obvious security reasons.
There is a Javascript screen capture API, but it requires the user to grant your site access to use it:
Using the Screen Capture API - Web APIs | MDN[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I write a page and use TempData to transfer information to other view.
the code like this
TempData["TP"]=tpDoc; //tpDoc is a xml file
In another view, I use
System.Xml.XmlDocument tpDoc = TempData["TP"] as System.Xml.XmlDocument;
above code is working in VS2019. But after I deploy to website, there is error:
Error.
An error occurred while processing your request.
so what is wrong in the code? Why it works in VS2019 and failed on Server?
|
|
|
|
|
You need to find out what the actual error is. Trying to diagnose a problem based solely on "an error occurred" is never going to work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The most common problem is that the file that loads into tpDoc is not where you think it is on the server or you do not have permissions to access is.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
SELECT DISTINCT does not work the way I want.
SELECT DISTINCT works for the class column but not for name_event column
If "MyId" is e.g. CW and there are 4 lines there but name_event should only be 2 pcs, but it shows 4 pcs
Now display:
World Championships
French Champioships
World Championships
World Championships
It should be:
World Championships
French Champioships
What am I doing wrong?
<pre> Dim MyDataAdapter As New SqlDataAdapter("SELECT DISTINCT class, nationality, name_event from statistics_results Where class = @class", MyConnection)
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@class", SqlDbType.VarChar, 10))
MyDataAdapter.SelectCommand.Parameters("@class").Value = MyId
Try
Dim dt As New DataTable()
MyDataAdapter.Fill(dt)
Dim natlist = dt.AsEnumerable().[Select](Function(r) r("nationality").ToString())
Dim natvalue As String = String.Join("- ", natlist)
litNat.Text = natvalue
Dim eventlist = dt.AsEnumerable().[Select](Function(r) r("name_event").ToString())
Dim eventvalue As String = String.Join("<br>", eventlist)
litEvent.Text = eventvalue
Catch exc As SqlException
Finally
MyConnection.Close()
MyConnection.Dispose()
End Try
|
|
|
|
|
What is your data?
kjell.ek wrote: SELECT DISTINCT class, nationality, name_event from statistics_results Where class = @class
All three columns (Class, Nationality, name_event) make it distinct. if you look at the data, those 4 rows are distinct from each other when you include all columns.
In other words if you do a
SELECT DISTINCT name_event from statistics_results Where class = @class
You will get two rows.
HTH
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
Hello Kjell.ek !
as distinct can be apply on one column,
you can use it this way :
SELECT id, distinct(name_event), class, nationality from statistics_results;
the sql engine will keep in the record with each name_event only one time.
DISTINCT statement acts at column level.
|
|
|
|
|
The OP is using a SqlDataAdapter , which means they're using Microsoft SQL Server.
That is not how DISTINCT works in SQL Server.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry I missed the data source, yes I use MS SQL server. Have tried the variants above but I get the wrong number of "name_event"
I get numbers according to how many rows there are in the selected class.
This is how it will be at a selected class. It should be 1 World Championships note 6
Tips on how to solve it?
World Championships
World Championships
World Championships
World Championships
World Championships
World Championships
DEU - FIN - FRA - NOR - POL - SWE
modified 6-Mar-23 8:07am.
|
|
|
|
|
Can you show what the result set is without the distinct please..
SELECT class, nationality, name_event from statistics_results Where class = 'xx'
|
|
|
|
|
Having trouble importing competition results from Excel to MS SQL Server with Asp.Net. Worked well until I added milliseconds. They are lost on import. Anyone with good tips on what the problem is?
MS SQL server Data Type: time(7)
Excel formatting for time results (Swedish Excel): tt:mm:ss,0
In asp.net
MyCommand.Parameters.Add(New SqlParameter("@total", SqlDbType.Time, 7))
MyCommand.Parameters("@total").Value = Trim(rad("Total"))
Time in Excel: 00:26:32,4
In SQL server: 00:26:32
I lost the milliseconds.
|
|
|
|
|
That Trim call suggests you're treating the data as a String . You should parse it to the correct type (TimeSpan ) before passing it to SQL.
Since your data is formatted for a culture which uses the comma as the decimal separator, you will need to ensure you use the correct CultureInfo when you parse the value.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for the tip
|
|
|
|
|
Format 109 is like "Jun 17 2012 2:00:29:147PM", so obviously [Start Date] is varchar already before the convert.
I suspect that that problem is that Excel thinks that this is a datetime value, and that's why the milliseconds are lost in transport. Excel is not really the best venue for strict data-typing, but rather the drivers makes some guesswork. You could try to format the column as text, but I am not sure it would help.
I never use OPENROWSET/OPENDATASOURCE to read Excel files myself. For one-offs I save the file as a CSV and import it with BCP. For imports on regular basis, I would write a client program for the task. Many people would go for a soluton with Integration Services.
|
|
|
|
|
Hi all,
where in the lifecycle of an asp.net page do you load the data for a gridview?
In Page_Load (which runs twice and check on !IsPostback is needed), in Page_LoadComplete (runs once) or in Page_Prerender (runs once)
I see better/smoother working of the pages when loading in Page_Loadcomplete event. How are your experiences?
I use Page_Prerender to set properties of a GridView other than DataSource and DataBind.
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
|
This is a horrible suggestion. Only tested SelectMethod.
AJAX starts yelling about Registerscripts issues
GridView can't set styling anymore via my Library (Node isues ??)
And Async leads to exception it needs a return Task (which it is).
Back to my way
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
So... yeah.
Don't show the code you tried, don't ask questions, don't describe any problems with proper detail, ...
Just bash the suggestion with summary judgement because it wasn't as simple to implement as you expected.
Sure.
|
|
|
|
|
Been working all weekend on it. Using the SelectMethod and Creating the method in codebehind is no problem. But when everything stays yelling except loading data I am done with it. Read enough on it. Have over 11,000 users of this site of mine and I am not gonna take risks.
Besides it is really strange that the SelectMethod in a page leads to a break in an UpdateProgress control in the masterpage. If I put that in comments, it is claiming for reducible nodes.
In Word you can only store 2 bytes. That is why I use Writer.
modified 2-May-22 10:14am.
|
|
|
|
|
And now in CODE
(used the ScottGu mentioned code in the link from first reply)
Created a clean asp.net 4.7.2 webforms project.
I have an ODATA service which is read via Unchase OData library
Index.Asp has the gridview:
<asp:GridView runat="server" ID="GrdTest"
AutoGenerateColumns="false" DataKeyNames="Id"
ItemType="MarinGlobalService.Models.User"
SelectMethod="GrdTest_GetData"
>
<Columns>
<asp:DynamicField DataField="Name" HeaderText="Name" />
<asp:DynamicField DataField="SurName" HeaderText="Surname" />
<asp:DynamicField DataField="GivenName" HeaderText="GivenName" />
<asp:TemplateField HeaderText="# of Usergroups">
<ItemTemplate><%# Item.UserGroup.Count %></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
My codebehind:
namespace TestGridView
{
public partial class Index : Page
{
private Default.Container container;
protected void Page_Init(object sender, EventArgs e)
{
Uri uri = new Uri("<a href="http:
container = new Default.Container(uri)
{
Credentials = CredentialCache.DefaultNetworkCredentials,
Timeout=3600
};
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
GrdTest.BackColor = System.Drawing.Color.LightGreen;
GrdTest.AlternatingRowStyle.BackColor = System.Drawing.Color.LightBlue;
GrdTest.RowStyle.BackColor = System.Drawing.Color.LightGray;
}
public IQueryable<User> GrdTest_GetData(int? maximumRows, int? startRowIndex)
{
if (maximumRows == null || startRowIndex == null)
return container.Users;
return container.Users.Skip(startRowIndex ?? 0).Take(maximumRows ?? 0);
}
}
}
This will lead to 1 gridview without paging and shows data.
Then I change my GridView to:
<asp:GridView runat="server" ID="GrdTest"
AutoGenerateColumns="false" DataKeyNames="Id"
ItemType="MarinGlobalService.Models.User"
SelectMethod="GrdTest_GetData"
AllowPaging="true" PageSize="5"
>
<Columns>
<asp:DynamicField DataField="Name" HeaderText="Name" />
<asp:DynamicField DataField="SurName" HeaderText="Surname" />
<asp:DynamicField DataField="GivenName" HeaderText="GivenName" />
<asp:TemplateField HeaderText="# of Usergroups">
<ItemTemplate><%# Item.UserGroup.Count %></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And the answer is:
[ArgumentException: must be reducible node]
System.Linq.Expressions.Expression.VisitChildren(ExpressionVisitor visitor) +97
System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node) +11
System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor) +12
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) +20
System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) +60
System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) +43
System.Web.Util.OrderingMethodFinder.VisitMethodCall(MethodCallExpression node) +43
System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) +12
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) +20
System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) +60
System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) +43
System.Web.Util.OrderingMethodFinder.VisitMethodCall(MethodCallExpression node) +43
System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) +12
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) +20
System.Web.Util.OrderingMethodFinder.OrderMethodExists(Expression expression) +38
System.Web.UI.WebControls.QueryableHelpers.IsOrderingMethodFound(IQueryable`1 queryable) +16
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +168
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +105
System.Web.UI.WebControls.ModelDataSourceView.ProcessSelectMethodResult(DataSourceSelectArguments arguments, DataSourceSelectResultProcessingOptions selectResultProcessingOptions, ModelDataMethodResult result) +393
System.Web.UI.WebControls.ModelDataSourceView.GetSelectMethodResult(DataSourceSelectArguments arguments) +86
System.Web.UI.WebControls.ModelDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +14
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.ModelDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +81
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +169
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +71
System.Web.UI.WebControls.GridView.DataBind() +5
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +93
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
System.Web.UI.Control.EnsureChildControls() +116
System.Web.UI.Control.PreRenderRecursiveInternal() +49
System.Web.UI.Control.PreRenderRecursiveInternal() +236
System.Web.UI.Control.PreRenderRecursiveInternal() +236
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4719
So why does Scott Guthrie gets paging and doesn't it work for me? And what is this reducible node?
Changing the GrdTest_Getdata method to:
public IQueryable<User> GrdTest_GetData(int? maximumRows, int? startRowIndex, out int? totalRowCount, string sortByExpression)
{
var users = container.Users;
totalRowCount = users.Count();
return users;
<pre>
}</pre>
will allow to have sortByExpression is set, but the collection does not get ordered by it.So AllowSorting will not give issues, only AllowPaging does.
In Word you can only store 2 bytes. That is why I use Writer.
modified 3-May-22 11:22am.
|
|
|
|
|
Sorting needs to be applied before the paging.
In your first example, you've returned a page of unsorted records, and are then trying to sort them. That's the most likely cause of the error.
In your second example, you've defined the sorting parameter, so your code is responsible for sorting the data. The model binding won't try to sort the returned data again.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|