|
Since we are creating rows dynamically, we would like to ensure that when a user creates more than one row of records for a particular form field, that the results are laid out correctly.
The following is an example of a row being created dynamically in GridView:
<asp:gridview ID="Gridview1" gridlines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:RequiredFieldValidator id="RequiredFieldValidator5" Font-Bold="true"
BorderColor="Red" BorderWidth="1" SetFocusOnError="true" runat="server"
Height="16px" ErrorMessage="REQUIRED FIELD" ControlToValidate="txtsourcename" /><br />
<asp:TextBox ID="txtsourcename" placeholder="Name..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Adress">
<ItemTemplate>
<asp:RequiredFieldValidator id="soaddress" Font-Bold="true"
BorderColor="Red" BorderWidth="1" SetFocusOnError="true" runat="server"
Height="16px" ErrorMessage="REQUIRED FIELD" ControlToValidate="txtsourceaddress" /><br />
<asp:TextBox ID="txtsourceaddress" placeholder="Address..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Income">
<ItemTemplate>
<asp:RequiredFieldValidator id="soincome" Font-Bold="true"
BorderColor="Red" BorderWidth="1" SetFocusOnError="true" runat="server"
Height="16px" ErrorMessage="REQUIRED FIELD" ControlToValidate="txtsourceincome" />
<asp:CompareValidator ID="CompareValidator1" runat="server" ValueToCompare="100000" ControlToValidate="txtsourceincome" ErrorMessage="Nust be greater than $100,000.00" Operator="GreaterThan" Type="Integer"></asp:CompareValidator>
<br />
<asp:TextBox ID="txtsourceincome" placeholder="Income..." runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" ">
<ItemTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add More"
onclick="ButtonAdd_Click" CssClass="grvAddButton" OnClientClick="return ValidateEmptyValue();" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True"><ControlStyle CssClass="grvDelButton" /></asp:CommandField>
</Columns>
</asp:gridview>
However, before they are submitted to the database, they are presented to the user to review his/her information before submitting to the database and code that does that is below (relevant code, I think).
If dtCurrentTable.Rows.Count > 0 Then
'//Next collection. Spouse Information
For Each row As DataRow In dtCurrentTable.Rows
Dim txtsourcen As String = TryCast(row.ItemArray(1), String)
Dim txtsourcea As String = TryCast(row.ItemArray(2), String)
Dim txtsourcei As String = TryCast(row.ItemArray(3), String)
lblPreviewSourceName.Text += txtsourcen & "<br />"
lblPreviewSourceAddress.Text += txtsourcea & "<br />"
lblPreviewIncomeSource.Text += txtsourcei & "<br />"
'get the values from the TextBoxes
'then add it to the collections with a comma "," as the delimited values
sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)
rowIndex += 1
Next
The issue is when we preview the data being presented, it looks like this:
Name: Ivory West
Indiana Jones
Address: 20 Ivory Street
65 Kay Dr
Income: 1000001
5820000
Is there a way to modify the codebehind I posted so data is laid out in the following format:
Name: Ivory West
Address: 20 Ivory Street
Income: 1000001
Name: Indiana Jones
Address: 65 Kay Dr
Income: 5820000
Many thanks for your help.
|
|
|
|
|
The simplest option would be to use a ListView control[^] bound to the data:
<asp:ListView id="previewList" runat="server">
<ItemTemplate>
<ul>
<li>Name: <%#: Eval("Name") %></li>
<li>Address: <%#: Eval("Address") %></li>
<li>Income: <%#: Eval("Income") %></li>
</ul>
</ItemTemplate>
</asp:ListView>
If dtCurrentTable.Rows.Count > 0 Then
previewList.DataSource = dtCurrentTable
previewList.DataBind()
End If
NB: You'll need to use the correct column names inside the three Eval("...") statements in the list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you Richard.
Yes, you are right this is much easier and cleaner.
Only issue is that it is very hard to access a label control in listview.
There needs to be a text like this:
Name, address and Income greater than $20,000.00 then followed by the values:
Name: Ivory West
Indiana Jones
Address: 20 Ivory Street
65 Kay Dr
Income: 1000001
5820000
|
|
|
|
|
samflex wrote: Only issue is that it is very hard to access a label control in listview.
Why would you need to access a label inside the ListView? You've already got the source data.
samflex wrote: There needs to be a text like this:
OK, now I'm really confused - isn't that what you started with?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm getting this error :
The requested content appears to be script and will not be served by the static file handler.
only when I redirect to a specific page, but I don't when I access it directly.
I googled a lot for this error but I couldn't solve it. What possibly could be the reason of it?
modified 29-Mar-17 16:16pm.
|
|
|
|
|
Member 12992094 wrote: I googled a lot for this error but I couldn't solve it. What possibly could be the reason of it? Hard to say since you haven't told us any of the things you tried.
However, first google result for me is this: asp.net - Script not served by static file handler on IIS7.5 - Stack Overflow[^]
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I tried using :
Quote: aspnet_regiis.exe -i
but I always get "asp-regiis" not recognized.
I also tried turning windows features on and off and then using the command but it didn't work.
Since I get this error only with this webpage, does it mean that there's something wrong with my code?
|
|
|
|
|
Member 12992094 wrote: but I always get "asp-regiis" not recognized. So, google that error and fix that.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I did, the command worked but it didn't solve the problem.
|
|
|
|
|
You'll need to keep troubleshooting it.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
You have to explain it with more details like
1. What are you trying to do ?
2. Where do you get this error ?
3. Post the actual error with your question.
4. Are you using any browser to access it ? If so what browser are you using?
5. If you are referring the script from other pages , show the page where you refer it from?
|
|
|
|
|
Quote: 1. What are you trying to do ?
I have a code editor, I want to save it's contents when the user clicks save and then redirect to "Index". I started getting this error after implementing this, but now I get it whenever I try to redirect to "Index" action method.
Quote: 3. Post the actual error with your question.
Here's the details of the error:
Detailed Error Information:
Module StaticFileModule
Notification ExecuteRequestHandler
Handler StaticFile
Error Code 0x80070032
Quote: 4. Are you using any browser to access it ? If so what browser are you using?
Yes, I'm using google chrome.
Quote: 5. If you are referring the script from other pages , show the page where you refer it from?
I redirect from a partial view after the user clicks send.
This is my controller:
StudentsCodes modelSC = new StudentsCodes();
MicroG4 m4 = new MicroG4();
public ActionResult Index()
{
modelSC.Student = (Student)CurrentUser;
var user = UserManager.FindById(((Student)CurrentUser).InstructorID);
modelSC.Instructor =(Instructor) user;
modelSC.path = "~/Content/" + CurrentUser.UserName + "/CompilerProject/src";
return View(modelSC);
}
And this is the partial view:
@model application.Models.NewFolder1.StudentsCodes
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<script src="/Scripts/codeMirror-2.37/lib/codemirror.js"></script>
<script src="/Scripts/codeMirror-2.37/mode/clike/clike.js" type="text/javascript"></script>
<link href="/Scripts/codeMirror-2.37/lib/codemirror.css" rel="stylesheet" type="text/css" />
<link href="~/Scripts/codeMirror-2.37/theme/lesser-dark.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/jquery-3.1.1.min.js"></script>
<link href="∼/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
</head>
<body>
@using (Html.BeginForm("SaveClass","Development"))
{
<div class="CodeMirror cm-s-lesser-dark cm-error cm-bracket" style="position:absolute;border:solid;top:150px;left:450px;width:700px">
<div class="navbar navbar-inverse" style="border:none">
<div class="container-fluid">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">
File
</a>
<ul class="dropdown-menu">
<li>@Html.ActionLink("New", "NewClass", "Development", null, new { @class = "modal-link" })</li>
<li>@Html.ActionLink("Save","SaveClass","Development",null,new { id="save"})</li>
<li>@Html.ActionLink("Delete", "DeleteFile")</li>
</ul>
</li>
<li>@Html.ActionLink("Compile", "Compile", "Development")</li>
<li>@Html.ActionLink("Run", "Run", "Development")</li>
</ul>
</div>
</div>
</div>
@Html.TextAreaFor(m=>m.code, new { id = "code" })
@Html.HiddenFor(s => s.path)
</div>
}
<div id="modal-container" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-content"></div>
</div>
<style>
.modal-content {
width: 600px !important;
margin: 30px auto !important;
}
</style>
<script>
$(function(){
$("#save").click(function(e){
e.preventDefault();
$(this).closest("form").submit();
});
});
</script>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-java",
theme: "cm-s-lesser-dark"
});
</script>
<script type="text/javascript">
$(function () {
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
});
$('body').on('click', '.modal-close-btn', function () {
$('#modal-container').modal('hide');
});
$('#modal-container').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
$('#CancelModal').on('click', function () {
return false;
});
});
</script>
</body>
</html>
|
|
|
|
|
|
 This is the Index view:
@model application.Models.NewFolder1.StudentsCodes
@{
ViewBag.Title = "Development";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="∼/Content/bootstrap.css" rel="stylesheet" />
<link href="∼/Content/bootstrap-theme.css" rel="stylesheet" />
<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script type="text/javascript" src="~/Scripts/jquery-3.1.1.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
</head>
<body>
<div class="navbar navbar-inverse " style="left:0; width:300px;bottom:3px; position:fixed; top:50px; color:#4e4a4a; font:bold;">
<ul class="nav nav-pills nav-stacked">
<li>
@Model.Student.UserName
<ul>
<li>
CompilerProject
<ul>
@{
var m = Directory.GetDirectories(Server.MapPath("~/Content/" + Model.Student.UserName + "/CompilerProject"));
foreach (var subdir in m)
{
var name = Path.GetFileName(subdir);
<li>
@name
<ul id="tree">
@foreach (var file in Directory.GetFiles(Server.MapPath("~/Content/" + Model.Student.UserName + "/CompilerProject/" + name)))
{
var filename = Path.GetFileName(file);
<li class="filelist" value="@("~/Content/" + Model.Student.UserName + "/CompilerProject/src/" + filename)">
@filename
</li>
}
</ul>
</li>
}
}
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div id="partial">
@{
Html.RenderAction("DevelopmentPartial", new { path1 = Model.path});
}
</div>
<script>
$(document).ready(function () {
$('.filelist').on('click', function (e) {
alert('Im clicked on filePath = ' + $(this).attr('value'));
var filePath = $(this).attr('value');
$('#partial').load('DevelopmentPartial', { path1: filePath });
});
});
</script>
</body>
</html>
|
|
|
|
|
Are you sure this is a partial view ? It looks like you have a full html there
|
|
|
|
|
I need to refresh this part only of the page when the user clicks on a list element, so I used partial view.
This is my first website, I'm not sure if I'm doing things right.
|
|
|
|
|
This is the part I need to refresh:
Capture.JPG - Google Drive[^]
It's an online IDE, I want the user to be able to display the contents of a file once he clicks on its name.
|
|
|
|
|
well, I don't know what happened now! The error is gone but still, if I access the "Index" directly all it's functionalities work, if I redirect from another action method, nothing works!
|
|
|
|
|
I solved it by reordering the scripts in the header of the main view
<meta name="viewport" content="width=device-width" />
<link href="∼/Content/bootstrap.css" rel="stylesheet" />
<link href="∼/Content/bootstrap-theme.css" rel="stylesheet" />
<script type="text/javascript" src="~/Scripts/jquery-3.1.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
:
Then I updated the script that loads the partial view:
<pre> <script type="text/javascript">
$(document).ready(function () {
$('.filelist').on('click', function (e) {
e.preventDefault();
alert('Im clicked on filePath = ' + $(this).attr('value'));
var filePath = $(this).attr('value');
$('#partial').load('@Url.Action("DevelopmentPartial", "Development")', { path1: filePath });
});
});
</script>
|
|
|
|
|
Are you saying that it is all working fine?
|
|
|
|
|
I still have a small problem with the drop-down menu doesn't show its list always, but I don't think it's relevant. So, yes I think it's all working fine.
|
|
|
|
|
|
Hello all
i am using telerik control in my ASP.NET MVC project, in the image control in the radEditor i cannot upload more than 4M image, so how i can upload image size more than 4M?
Please help
Thank you
|
|
|
|
|
|
All I am trying to open a new Angular 2.0 Project, I don't why did they make it so complex.
I selected File menu -> new Project -> C# -> then Asp.Net Core Angular 2 Starter Application (.Net Core), then I am getting the following error
The imported project C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props was not found. Confirm that the path in the <import> declaration is correct, and that the file exists on disk. C:\Users\aaleem01\Desktop\Angular2Apps\MyAngular2App\MyAngular2App\MyAngular2App.xproj
Can anybody please help me in fixing this issue, it is not even opening the solution saying error in creating the project. Any help is going to be very helpful.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|