ASP.NET

124K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi

In my ASP.net web app I am writing code that loops through a GridView and inserts data into a SQL table.
I want to prevent duplicates based o two columns [Username] and [Item ID].

What I the best way to do this?
0
Get expert help—faster!
LVL 12
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Hi

I am designing an online SQL database for ordering products on my ASP.net web app.
I am trying to work out the best way to handle the "Basket".
The easiest way in my mind would be to retain the IDs of the items that
a user selects using cookies so that if the user leaves the page and comes
back I can use the cookies to show which items were selected.

An alternative option would be to have a SQL table that is structured
like my Products table. I would insert the user's selected items into this table.

I could also use my Orders table and show the Order status as being in the basket.


I'm looking for a little feedback on this. Thanks
0
Hi experts,

I saw this example on Grouping with linq.
https://ole.michelsen.dk/blog/grouping-data-with-linq-and-mvc.html

I also saw this example.
https://stackoverflow.com/questions/1160420/how-do-i-group-data-in-an-asp-net-mvc-view

I have a ASP.NET MVC application using C# , Razor and Entity Framework, database first model.

I'm using the Orders table from the Northwind database.

My application directory looks likes this:

AppDirectory.PNG
My controller looks like this:

Controller.PNG
My view looks like this:

View.PNG
When I run my app it shows the Orders table.

Run.PNG
Now I want to Group it by Customer ID.

I looked at this example to try to group my example but I'm having a hard time grouping it.
https://ole.michelsen.dk/blog/grouping-data-with-linq-and-mvc.html

How do I revise my example so it groups by CustomerID.
So my View should look like this:

DesiredSort.PNG

This is my current code for my Controller:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using NorthwindApp.Models;

namespace NorthwindApp.Controllers
{
    public class HomeController : Controller
    {
        private NorthwindEntities db = new NorthwindEntities();

        // GET: /Home/
        public ActionResult Index()
        {
            

            // Order by 

Open in new window

0
I wonder if this is because of IIS and how the site is setup

1. My coworker set up an IIS site like this

image
2. You see there's a path assets-->pages-->img-->login the images in this path aren't showing up. I've tried
/assets/pages/img/login/bg1.jpg,
../assets/pages/img/login/bg1.jpg
~/assets/pages/img/login/bg1.jpg

3. Images under this folder show up "img". This is in the root folder of that "Demo" site. In the image above, I've marked the folder with XX. I have it like this ~/img/CSI-logo.png

When I look at Chrome's console, that path is translated to this (has "demo" in the beginning of it)
2.png
4. If I hard code the "demo" root folder, then the image shows up /Demo/assets/pages/img/login/bg1.jpg

Why is this?  I don't want to hardcode /Demo/ How can I fix this? what path do I need to use?
0
I'm working on some convoluted code (developer got frustrated by his own code and left a few months ago!)

1. I get a date string like this {"Year":2017,"Month":9,"Day":30}

2. I want to get the date of out it and concat it ...so 2017/09/30

I want to do it in this routine the developer has. I have to put in a quick fix

 public static DateTime? TryParseStringToDate(string data)
        {
            DateTime date;

           //*** here... parse it here, get 2017/09/30 

            if (DateTime.TryParse(data, out date))
                return date;

            return null;
        }

Open in new window

0
I bought this template and this is the front page

https://keenthemes.com/preview/metronic/theme/admin_4/page_user_login_5.html

I replaced the images in my project but the images are too bright. I was looking at some sites and there's a way to apply a background color to make the images a little bit darker.

I looked at our own company website and they've darkened the images with this CSS. I don't think I need all that. The key is "background". How can I apply it to the site? where does it go? if I know where I can put it, then I can make the change in my code.


body .page #hero .inner-wrap {
  background: rgba(9, 9, 9, 0.6);
  padding: 0;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  max-height: 700px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}

Open in new window

0
Hi Experts,

Party politics and partly the other dev doesn't want to change the data format he is sending I've been left with this problem.

I have an integer made up of 3 parts for example: 131110 I need to display this as 13:11:10.

How do I efficiently split this using asp.net VB.

This is further complicated by having to drop any leading zeros so:

90807 needs to show as 9:8:7 (the data width is 6, so assuming the left most digit to be 09)
081207 shows as 8:12:7
etc

Can anyone point me in the right direction please.

Andy
0
Hi experts,

I'm learning to work with hyperlinks in MVC views.
So I created the example below to illustrate my question.

I have a ASP.NET MVC 5 application. I'm using C# and Razor.

I have an example that uses database first model.
I'm using the Employees table from the Northwind sql server database.

My application directory looks like this.

p1.PNG
My model looks like this:

EntityModel.PNG
My controller looks like this:

HomeController.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using NorthwindApp.Models;

namespace NorthwindApp.Controllers
{
    public class HomeController : Controller
    {
        // ASP.NET Scaffolding in Visual Studio 2013
        // http://www.asp.net/visual-studio/overview/2013/aspnet-scaffolding-overview
        // Getting Started with Entity Framework 6 Database First using MVC 5
        // http://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database

        private NorthwindEntities db = new NorthwindEntities();

        //***************************** INDEX *****************************
        // GET: Home
        public ActionResult Index()
        {
            var employees = db.Employees.Include(e => e.Employee1);
            return View(employees.ToList());
        }
        //***************************** INDEX 

Open in new window

0
Hi

What is the best ASP.net control t use to build a list with multiple columns where you can edit values
in the list?

Thanks
0
Hi. I am looping through a GridView's rows gathering cell values using the code below. If the cell is blank I get  
How do I automatically convert this to a blank string
      For r = 3 To oGridViewRow.Cells.Count - 1

                        oCellValue = oGridViewRow.Cells(r).Text
         
                    Next

Open in new window

0
Free Tool: Site Down Detector
LVL 12
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Hi

I am using the following code to loop through my ASP.net GridView and gather each cell value and the header text for a cell.
I have marked the problem line with the word "BLANK". For some reason this is returning blanks instead of the header text of the GridView.


   Function oCreateOrder() As String

        Dim oID As String
        Dim oType As String
        Dim oCategory As String
        Dim oOrderQty As String
        Dim oTextBox As TextBox
        Dim oGridViewRow As GridViewRow
        Dim oHeaderText As String
        Dim oCellValue As String
        Dim blnAtLeastOneOrder As Boolean = False
        Dim i As Integer
        Dim r As Integer

        Try

            For i = 0 To Me.GridView1.Rows.Count - 1

                If Me.GridView1.Rows(i).BackColor = Drawing.Color.Cyan Then

                    blnAtLeastOneOrder = True

                    'Get the value out of the TextBox template column
                    oGridViewRow = GridView1.Rows(i)
                    oTextBox = oGridViewRow.FindControl("txtOrderQty")
                    oOrderQty = oTextBox.Text

                    For r = 3 To oGridViewRow.Cells.Count - 1
                        oHeaderText = Me.GridView1.HeaderRow.Cells(r).Text 'BLANK
                        oCellValue = oGridViewRow.Cells(r).Text
                    Next




                End If

            Next

            Response.Redirect("Checkout")

        Catch ex As Exception
            oCreateOrder = False
     

Open in new window

0
Hi

In my ASP.net web app I want to load data to a GridView and hide any columns where all data is blank or null.
I know how to hide a columns in the  Row_Created event but I need to check all the data before I know that it is blank.
Should I loop through a datatable first? What would the code look like for this?


Thanks
0
Hi

I am trying to use the following css style "HeaderFreez" on my ASP.net page below to freeze the header of my GridView
but it isn't working
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Steel._Default" %>

<!DOCTYPE html>

<style type="text/css">
.HeaderFreez
{
	position:relative ;
	top:expression(this.offsetParent.scrollTop);
	z-index: 10;
}
</style>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    </head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Panel ID="Panel1" runat="server">
            <table>
                <tr>
                    <td></td>
                    <td>
                        <asp:Label ID="lblUsername" runat="server" Text="Username"></asp:Label>
                    </td>
                    <td></td>
                    <td>
                        <asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
                    </td>
                    <td></td>
                    <td></td>
                    <td>

                    </td>
                    <td>

                        &nbsp;</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
              

Open in new window

0
I need some help creating a SQL statement that will display the output in different view.

My current table data looks like this:

VendorName  MonthAsDate  MonthYear  Count
Vendor1     1/1/2018     2018-01    120
Vendor2     1/1/2018     2018-01    9
Vendor3     1/1/2018     2018-01    4877
Vendor4     1/1/2018     2018-01    40
Vendor5     1/1/2018     2018-01    23
Vendor1     2/1/2018     2018-02    97
Vendor2     2/1/2018     2018-02    6
Vendor3     2/1/2018     2018-02    4455
Vendor4     2/1/2018     2018-02    42
Vendor5     2/1/2018     2018-02    60
Vendor1     3/1/2018     2018-03    89
Vendor2     3/1/2018     2018-03    12
Vendor3     3/1/2018     2018-03    4517
Vendor4     3/1/2018     2018-03    49
Vendor5     3/1/2018     2018-03    32
Vendor1     4/1/2018     2018-04    82
Vendor2     4/1/2018     2018-04    12
Vendor3     4/1/2018     2018-04    4109
Vendor4     4/1/2018     2018-04    48
Vendor5     4/1/2018     2018-04    130
Vendor1     5/1/2018     2018-05    113
Vendor2     5/1/2018     2018-05    9
Vendor3     5/1/2018     2018-05    4275
Vendor4     5/1/2018     2018-05    57
Vendor5     5/1/2018     2018-05    17

Open in new window


I'd like a view that outputs the data like this:

MonthYear  Vendor1  Vendor2  Vendor3  Vendor4  Vendor5
2018-01	   120      9        4877     40       23  
2018-02	   97       6        4455     42       60
2018-03	   89       12       4517     49       32
2018-04	   82       12       4109     48       130

Open in new window


Can't this be done with an advanced SQL statement?

Thanks.
0
Hi

In my ASP.net GridView shown below what additional markup will I use to add an additional template field
that acts as a text box for users to type a numeric quantity in?

<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" AllowSorting="True">   
            <Columns>


                <asp:TemplateField HeaderText="Order" HeaderStyle-Font-Size ="Small" 
                                            ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="DarkRed" 
                                            ControlStyle-Font-Size ="Smaller">
                    <ItemTemplate>
                        <asp:Button ID="Button10" runat="server" 
                      CommandName="MyButton5" 
                      CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>"
                      Text="Order" />
                    </ItemTemplate>
                          <ItemStyle HorizontalAlign="Right" />
                    <ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="DarkBlue" />
                    <HeaderStyle Font-Size="Small" />
                </asp:TemplateField>

                
                <asp:TemplateField HeaderText="Order" HeaderStyle-Font-Size ="Small" 
                                            ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="DarkRed" 
                                            ControlStyle-Font-Size ="Smaller">

Open in new window

0
I saw this example.
https://jsfiddle.net/krdy14sz/

In that example using JavaScript to prevent typing in a html textbox

How do i do the same example using a ASP.Net TextBox?
My ASP textbox looks like this:
Just not sure how to call the JavaScript function from the TextBox because the same call from above example didn't work.

<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
0
Hi, what is the simplest way to change class library with one public method (returning ADO.NET DataTable) to Web API?
Why would I need to convert class library to Web API? Can it be done without ASP.NET Web API/MVC project?

Thank you in advance.
0
I'm using Postman to send a command to an API method. I put a debug step and the code stops in the API method but one of the parameters comes out as NULL.

1. This is the API method signature. I see that "[FromBody]". Not sure if this is what's causing the null

 [IncludeInApiExplorer]
        [Route("CMDB/Asset/{id}")]
        public ResultModel Post(Guid id, [FromBody]CMDB_Asset asset)
        {

Open in new window


2. Documentation has this as sample request format

api
or this

image
3.  I used postman to build the parameters and I have this. I'm doing it on my local code.

http://localhost:3180/CMDB/Asset/6da60bdc-0272-4f04-89e6-fb48dbc51d31?CMDB_ID=fe0d7fe1dbdd5704b3b33cae7c9619a5
&Schedule=206UK&Serial=7JRDNN2&Manufacturer=test Inc.&Model=test&CustomerReference&CDF01=425003yyy7-TASK0089972&CDF02&CDF03&CDF04&CDF05=GBLHR04&CDF06&CDF07=In stock&CDF08=Available&CDF09&CDF10&SiteAddress=test, Springfield Dr&SiteCity=Leatherhead&SiteState=Surrey&SiteLocale&SiteRegion&SitePostalCode&SiteCountry=GB

Open in new window


4. I run it in Postman. Step thru the code. It gets to this line of code but asset is null. "id" is not null..id comes out as 6da60bdc-0272-4f04-89e6-fb48dbc51d31.

 public ResultModel Post(Guid id, [FromBody]CMDB_Asset asset)

How do I need to call this API?
0
Hi,

I have installed a service reference on my asp.net forms website. But when I'v e done so I get this error:

 Reference.svcmap: Could not load file or assembly 'ServiceStack.ServiceInterface, Version=3.9.70.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Open in new window

I can't figure out what reference I'm missing. Can someone help me understand how to fix this I'm very grateful.

Peter
0
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

I am currently working on a project that uses jQuery/jqGrid(Version 4.4.4, old version, I know...).

I have a custom formatter which gives me the ability to click on a hyperlink for editing, saving, and canceling. Code is posted below
"<a href='javascript:void(0)' class='anchor usergroup_name link' onclick=\"editRow.call(this,'" + rowobject.rowId + "')\">edit</a>" + "|"
                    + "<a style='display:none' href='javascript:void(0)' class='anchor usergroup_name link' onClick=\"saveRow.call(this,'" + rowobject.rowId + "')\">save</a>" + "|"
                    + "<a href='javascript:void(0)' style = 'display:none' class='anchor usergroup_name link' onClick=\"cancelRow.call(this,'" + rowobject.rowId+ "' )\">" + 'cancel' + "</a>";

Open in new window


I pass the hyperlink itself, and I pass a value (rowObject.rowId = the unique identifier of the rowObject).  

Now when the user clicks a hyperlink, it will eventually call $(this).closest(".ui-jqgrid-btable").jqGrid('saveRow', rowId) or editRow or restoreRow. For items 1-10 it works fine, but when I get to the second page of items, it stops working.

This is because the JQgrid has the rowId set back to one, where the item has an iD of 11. Picture of what I mean below.
[embed=fiexample of rowId mismatchle 1329000]

So in short, each object that is passed to the JQgrid has a unique identifier. I try to access that row by calling the objects unique identifier. However, on page changes, the rowId for jqGrid reverts back to 1.

How can I make it so I can edit these objects on the second page

Thank you for you help.
0
Hi

I have two GridViews on my ASP.net web page in two divs as shown in the following markup code.
When I bind data to them the left GridView shows at the top of the page but I have to scroll down to see the right
GridView. How do I show both of them at the top of the page?

          <asp:Panel ID="Panel2" runat="server" Visible="False">

        <div style="width:20%; float: left;">
            <asp:GridView ID="GridView1" runat="server"></asp:GridView>
        </div>
        <div style="width: 80%; margin-left:1%; float: right;">
     
 
                <asp:Label ID="lblSuccess" runat="server" ForeColor="#003300"></asp:Label>
                <asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>
                
      <asp:GridView ID="GridView2" runat="server" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="100%" AllowSorting="True">   
            <Columns>

       <asp:TemplateField>
            <ItemTemplate>
               <asp:CheckBox ID="chkSelected" runat="server"  />

            </ItemTemplate>
            <ItemStyle HorizontalAlign="Right" />
        </asp:TemplateField>

                <asp:TemplateField HeaderText="Order" HeaderStyle-Font-Size ="Small" 
                                            ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="DarkRed" 
                                            ControlStyle-Font-Size ="Smaller">
                    <ItemTemplate>
      

Open in new window

0
In my ASP.net web app I set the allow sorting property of my data bound GridView to true
    <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="100%" AllowSorting="True"> 

Open in new window


but when I click on one of the headers I get the following error

1
0
Hi
I am using the following GridView in my ASP.net web app. The check box and button field appears on the left of my data.
How do I get it to rather appear on the right? Thanks

                <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="100%">   
            <Columns>

                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkSelected" runat="server"  />
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Strongly Disagree" HeaderStyle-Font-Size ="Small" 
                                            ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="DarkRed" 
                                            ControlStyle-Font-Size ="Smaller">
                    <ItemTemplate>
                        <asp:Button ID="Button10" runat="server" 
                      CommandName="MyButton5" 
                      CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"
                      Text="Strongly Disagree" />
                    </ItemTemplate>
                    <ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="DarkRed" />
                    <HeaderStyle Font-Size="Small" />
                </asp:TemplateField>
            </Columns>

            <FooterStyle BackColor="White" ForeColor="#000066" />
            

Open in new window

0
Hi

I am building an ASP.net web app where clients can go on and select items in a GridView. When they are done they will be able
to go to a checkout page and pay for the items.

I am looking for some advice on how to approach this. I suspect that cookies are the best way to approach this.


Thanks
0
Hi

In my ASP.net Web application I want to load product data into a GridView so that a user can select one or multiple items
by clicking buttons or check boxes. I then want them to be able tp proceed to  a check out page.
At this time I won't be using images in the  GridView.

Does anyone have an example of the html for such a GridView.

Thanks
0

ASP.NET

124K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications