|
hi to everyone
i need your help
i need to add GridView to a webpage using c#, without declare it in the page.aspx. is it possible?
i've tried in this way, but it never work
here the aspx
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<section ID="normalElement" runat="server"></section>
<section ID="adminPanel" runat="server"></section>
<section ID="myC" runat="server"></section>
</asp:Content>
here the c#
GridView view = new GridView();
DataTable tbl = new DataTable();
DataColumn idCol = tbl.Columns.Add("COL_A");
idCol.DataType = System.Type.GetType("System.String");
DataColumn nameCol = tbl.Columns.Add("COL_B");
nameCol.DataType = System.Type.GetType("System.String");
DataColumn descrCol = tbl.Columns.Add("COL_C");
descrCol.DataType = System.Type.GetType("System.String");
DataColumn delCol = tbl.Columns.Add("COL_D");
delCol.DataType = System.Type.GetType("System.Boolean");
view.DataSource = tbl;
view.DataBind();
myC.Controls.Add(view);
but when i run the page, never appears on the page.
i've tried to add an empty row, but never change
so: is it possible doing what i'm trying to do?
thank you
|
|
|
|
|
With your code, you have created the table tbl but you did not bind any data to it, those are columns you defined with no data so it will not be visible on the page.
Try something like below -
Have a place holder as below -
<asp:PlaceHolder ID="ph" runat="server" />
I am able to add the grid on page with below code.
protected void Page_Load(object sender, EventArgs e)
{
List<string> countrylist = new List<string>() { "India", "US" };
GridView grid = new GridView();
grid.AutoGenerateColumns = true;
grid.DataSource = countrylist;
grid.DataBind();
ph.Controls.Add(grid);
}
modified 20-Sep-20 21:01pm.
|
|
|
|
|
<asp:Panel id="panel_left" runat="server" Visible="false">
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdbGVRow" />
</Triggers>
<ContentTemplate>
<div class="row" style="padding-top:10px;">
<div class="col-md-12">
<div class="table-responsive" style="border: thin; overflow-y: hidden;">
<asp:GridView ID="grid_contact" runat="server" AutoGenerateColumns="False" DataKeyNames="C_ID"
OnRowDataBound="gv1_RowDataBound" OnPageIndexChanging="grid_contact_PageIndexChanging" AllowPaging="true" PageSize="10"
CssClass="table table-bordered table-hover" AutoPostBack="true" >
<HeaderStyle CssClass="table-bordered table-hover" Height="10px"/>
<PagerStyle cssClass="gridpager" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField HeaderText="Detail" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:RadioButton ID="rdbGVRow" runat="server" OnCheckedChanged="radioChecked" AutoPostBack="true"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate><%#Eval("NAME")%> <%#Eval("LNAME")%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="C_ID" HeaderText="Contact Id" SortExpression="C_ID" />
<asp:BoundField DataField="TITLE" HeaderText="Job Title" SortExpression="JOB TITLE" />
<asp:BoundField DataField="Added_on" HeaderText="Added On" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate><div class="label label-lg label-success"><%#Eval("STATUS")%> </div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
|
|
|
|
|
Did you face any error?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Use this code,
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Radiobuttonlb = e.Row.FindControl("rdbGVRow") as Radiobutton;
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
}
also set
ClientIDMode="AutoID" for the Radiobutton
|
|
|
|
|
I am looking for information about how to integrate asp.net core or mvc and angular2, any information I would appreciate, thanks
|
|
|
|
|
Google will find you plenty.
|
|
|
|
|
|
Always best to try your own searches before posting questions.
|
|
|
|
|
The basics of .NET Core are, that this framework is highly extensible. There is nothing, by default in it. You add everything from scratch. Angular, Node.js, NPM etc. They are all added by the developers and you have to add them yourself as well.
There are however, templates provided, that you can use to create a new project.
Have a look here, Create an Angular 2 and .NET Core app that can be edited using Visual Studio 2017 - jonhilton.net, this provides a command that you can use to install extra packages and then utilize them in your projects by creating a new template-based project.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Just wondering if anyone has had some luck with integrating lightSlider, bootstrap and MVC.
I wrote something from scratch that worked better, but had trouble overlaying navigation over the pictures, otherwise it resized correctly with phones and desktops.
So I decided to try lightSlider since Sputnik was using it. Seems well written, but I can't figure out how to resize the pictures for various devices.
It's too tall for desktop use and wanted to scale it down. On phones in portrait, I get full picture height but it overflows hidden; and landscape it's just too tall for the screen.
You can see what I have here
http://50.20.227.154/Portfolio/Viewer/0
Just poking around for insight.
If it ain't broke don't fix it
|
|
|
|
|
Well I skipped over fixing the lightSlider and added the light-gallery to it. Then used my bower.json file to load both plugins automatically, and gulp to distribute the files correctly throughout the project. After getting all of that to work, I went back to doing research on the lightSlider and started going through a handful of tutorials.
Finally found this one
Js Tutorial - lightSlider - A lightweight touchable responsive Content slider
Which seemed to offer the best information on how to set it up.
So if all boiled down to the config file. So to save any one having the same trouble, here's a sample of what I used.
Still messing with the responsive properties to see how they work. Now that I have a stronger foundation, I can now build it out.
Overall, this lightSlider plugin is pretty slick, and the guy did a nice job writing it.
$(document).ready(function () {
$('#lightSlider').lightSlider({
item: 1,
autoWidth: false,
slideMove: 1,
slideMargin: 10,
addClass: '',
mode: "slide",
useCSS: true,
cssEasing: 'ease',
easing: 'linear',
speed: 400,
auto: false,
loop: false,
slideEndAnimation: true,
pause: 2000,
keyPress: false,
controls: true,
prevHtml: '',
nextHtml: '',
rtl: false,
adaptiveHeight: false,
vertical: false,
verticalHeight: 500,
vThumbWidth: 100,
thumbItem: 10,
pager: false,
gallery: true,
galleryMargin: 5,
thumbMargin: 5,
currentPagerPosition: 'middle',
enableTouch: true,
enableDrag: true,
freeMove: true,
swipeThreshold: 40,
responsive:
[
{ breakpoint: 1260, settings: { item: 2, thumbitem: 10, gallery: true, pager: true } },
{ breakpoint: 900, settings: { item: 2, thumbitem: 8, gallery: true, pager: true } },
{ breakpoint: 700, settings: { item: 1, thumbitem: 6, gallery: false, pager: true } },
{ breakpoint: 600, settings: { item: 1, thumbitem: 4, gallery: false, pager: true } }
],
onBeforeStart: function (el) { },
onSliderLoad: function (el) {
el.lightGallery({
selector: '#lightSlider .lslide',
subHtmlSelectorRelative: true
});
},
onBeforeSlide: function (el) { },
onAfterSlide: function (el) { },
onBeforeNextSlide: function (el) { },
onBeforePrevSlide: function (el) { }
});
});
If it ain't broke don't fix it
|
|
|
|
|
im using grid view, i set page size to 10 record and also put search bar to search record, the problem is that when i search record it shows records that is about 30 on page change it is reset to the default rather then show record on page 2 related to my search
|
|
|
|
|
You mean, you need to trim down the amount of results shown on the page?
Why are you selecting more than 10 records in the very first place? You should return only 10 records, on that page and then later on select the next 10 records, and so on.
You should also look at Pagination in ASP.NET, that will help you a lot in showing a better UX to the readers, who want to get something from your web application, read the following posts,
GridView Examples for ASP.NET 2.0: Paging and Sorting the GridView's Data
How To Implement Paging in GridView Control in ASP.NET
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hello Dudes,
I need a project on Employee leave management with timesheet, payroll and leave management using Asp.Net C#. please anyone provide me that code.
Thanks in advance.
Prasad
modified 8-May-17 14:49pm.
|
|
|
|
|
Hi Naveen,
It is not possible to get everything in a single project online. It is better to made it according to the requirement. If you want i can help you in to create that project.
|
|
|
|
|
Hi geeta goel, thank you for the replay. but at least i need leave management code and database tables. remaining parts i can implement.
|
|
|
|
|
This site is not here to provide code to order; try RentaCoder.
|
|
|
|
|
Hi Geeta goel,
Could you please give me brief description about salary structure in MNCs and also give me clarification about Leave management & Vacation Management. is leave and vacation both are same or different? how salaries calculated if any leave or vacation in a month. please give me example with 2 employees info.
Eagerly waiting for your response.
Thanks in Advance,
Prasad
|
|
|
|
|
Hello Naveen,
Leave & Vacation management both have different aspects in Corporate.
Leave also have a structure or we can say there are different types of leaves are there and they are alloted to the employees on some logical basis.
There are different ways of salary structure in MNC's. In some company's it is deciding on the grade levels and in some it is deciding on the experience basis.
It is not explained in a single paragraph. There are many logics behind the salary & leave management.
|
|
|
|
|
Thank you for your response.
Actually i'm implementing HRMS application. i want to include all those features like Leave,Vacation,Task,Employee Loans... etc. into one application. So, i need full clarity on Leave, Vacation and Salary Management. Till now i've completed upto employees management and task management. So, please give me at-least 50% knowledge.
What are the different ways for salary structures?
|
|
|
|
|
Hello Naveen,
There are different kinds of salary structure.
1. Hourly basis pay
2. Monthy basis pay
3. Weekly basis pay
4. Bi-weekly basis pay
It also depends that you are implementing the HRMS application for which country - India or USA or any other. There are some differences in their salary structures.
And also in salary structure, you can consider some more attributes.
I have given you a short description of the salary structures. You need to study in brief if you want to implement all full features.
|
|
|
|
|
|
I don't have time to give you the table structures, but I can tell you that you want to design the solution with effective dates; meaning Emp A is currently earning 4 hrs per month towards his PTO (paid time off), next year he will be earning 4.25 hrs per month, etc.
You will need to have a background job which adds each employee's accrued hours to a current balance bucket, also you want to have an end of year job which zeros out any unused PTO (use it or lose it).
You will need to take into consideration that if Employee A is asking for a week of vacation in July, but it is only February, you will have to perform logic such as, Current Balance + future accrued balance is that enough time ?
Also take into consideration if 3 guys from the same department want to take time off the same week August to go fishing. Will you be able to run the business ?
Leave management is a tricky thing. Lots of things to consider.
Good luck.
|
|
|
|
|
We have a spec to generate PDF from HTML inputs and send as email attachments.
We were able to use the examples on the article below to accomplish that:
https://www.aspsnippets.com/Articles/iTextSharp-Generate-PDF-in-Memory-and-send-as-Email-Attachment-using-C-VBNet-and-ASPNet.aspx
The issue is that because the article uses HTMLWorker, it is extremely difficult to format data with HTMLWorker.
So, I attempted to convert HTMLWorker to XMLWorker.
Right now, it works by inserting records into the database but the email is not getting sent.
Any ideas what I am doing wrong?
Imports iTextSharp.tool.xml
Imports iTextSharp.text.pdf
Imports System.IO
Imports System.Text
Imports System.Data
Imports System.Net
Imports System.Net.Mail
Imports iTextSharp.text.html.simpleparser
Imports System.Data.SqlClient
Imports System.Runtime.CompilerServices
Partial Class _Default
Inherits System.Web.UI.Page
Private strConn As String = ConfigurationManager.ConnectionStrings("constr").ToString()
Private sqlCon As SqlConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
End If
End Sub
Protected Sub Insert(ByVal sender As Object, ByVal e As EventArgs)
System.Threading.Thread.Sleep(5000)
Try
Dim table As New DataTable()
Using con = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Using cmd = New SqlCommand("INSERT INTO Policies(userid,entrydate,signature, email) VALUES(@empID, @lDate,@signature, @email)", con)
Using da = New SqlDataAdapter(cmd)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@empID", txtUserName.Text)
cmd.Parameters.AddWithValue("@lDate", txtDate.Text)
cmd.Parameters.AddWithValue("@signature", txtSignature.Text)
cmd.Parameters.AddWithValue("@email", txtEmail.Text)
da.Fill(table)
End Using
End Using
End Using
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(0) {New DataColumn(" ")})
' dt.Rows.Add(txtaffirmation.Text)
SendPDFEmail(dt)
'If the message failed at some point, let the user know
Label1.ForeColor = System.Drawing.Color.Blue
Label1.Text = "Success!<br> A copy of the completed form has been sent to your inbox. If you do not receive an email within 5 minutes (usually immediately), check your spam box."
'Reset markup controls
txtFullName.Text = ""
txtUserName.Text = ""
txtSignature.Text = ""
txtDate.Text = ""
txtEmail.Text = ""
Catch ex As Exception
'If the message failed at some point, let the user know
Label1.ForeColor = System.Drawing.Color.Red
Label1.Text = ex.Message
End Try
''reset markup controls
'ClearTextBoxes(Page)
End Sub
Private Sub SendPDFEmail(ByVal dtb As DataTable)
Dim strHtml As String
Dim memStream As New MemoryStream()
Dim strWriter As New StringWriter()
Dim FullName As String = txtFullName.Text
Dim user As String = txtUserName.Text
Dim signedName As String = txtSignature.Text
Dim lDate As String = txtDate.Text
Dim body As String = "<br />"
body = body & "<table style=""background-color:#F8F8F8"" cellspadding=""2"" border=""0"" width=""100%"" >"
For Each column As DataColumn In dtb.Columns
body = body & "<td style=""color: black"" align=""Left"">" & txtaffirmation.Text & "</td></tr></table><br>"
Next
body = body & " <br><br>"
body = body & "<table style=""background-color:#F8F8F8"" cellspadding=""2"" border=""0"" width=""100%"" >"
body = body & "<tr><td align=""left"">" & FullName & "</td>"
body = body & "<td align=""left"">" & user & "</td></tr>"
body = body & "<tr><td align=""left"">Employee Name</td>"
body = body & "<td align=""left"">Employee ID</td></tr>"
body = body & "<tr><td style=""font-family:Brush Script Std"" align=""left"">" & signedName & " </td><td align=""left"">" & " " & "</td>"
body = body & "<td align=""left"">Employee Signature</td><td align=""left"">" & " " & "</td></tr>"
body = body & "<tr><td align=""left"">" & lDate & "</td><td align=""left"">" & " " & "</td></tr>"
body = body & "<td align=""left"">Date</td><td align=""left"">" & " " & "</td></tr></table>"
strHtml = strWriter.ToString()
strWriter.Close()
strWriter.Dispose()
Dim strFileShortName As String = "test" & DateTime.Now.Ticks & ".pdf"
Dim strFileName As String = HttpContext.Current.Server.MapPath("reports\" & strFileShortName)
Dim docWorkingDocument As iTextSharp.text.Document = New iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate(), 1, 1, 0, 0)
Dim srdDocToString As StringReader = Nothing
Try
Dim pdfWrite As PdfWriter
pdfWrite = PdfWriter.GetInstance(docWorkingDocument, New FileStream(strFileName, FileMode.Create))
srdDocToString = New StringReader(strHtml)
docWorkingDocument.Open()
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWrite, docWorkingDocument, srdDocToString)
Catch ex As Exception
Response.Write(ex.Message)
Finally
If Not docWorkingDocument Is Nothing Then
docWorkingDocument.Close()
docWorkingDocument.Dispose()
End If
If Not srdDocToString Is Nothing Then
srdDocToString.Close()
srdDocToString.Dispose()
End If
End Try
Using memoryStream As New MemoryStream()
Dim writer As PdfWriter = PdfWriter.GetInstance(docWorkingDocument, memoryStream)
docWorkingDocument.Open()
'insert image into pdf
Dim logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/fc3.png"))
logo.SetAbsolutePosition(29, 680) ' insert top left
'logo.ScaleToFit(350.0F, 300.0F) ' reduce image size
docWorkingDocument.Add(logo)
docWorkingDocument.Close()
Dim bytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
Dim mm As New MailMessage("NoReply@email.com", txtEmail.Text)
mm.Subject = "From: " & txtFullName.Text
mm.Body = "Please see attached copy of your completed form. "
mm.Attachments.Add(New Attachment(New MemoryStream(bytes), user & ".pdf"))
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.EnableSsl = False
Dim NetworkCred As New System.Net.NetworkCredential()
NetworkCred.UserName = "myemail@gmail.com"
NetworkCred.Password = "mpassword"
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 587
smtp.Send(mm)
End Using
End Sub
End Class
|
|
|
|
|