|
Hi,
I want to fetch data from SQL database, and display the same on my HTML page in table format using Angular JS.
I am able to get the data in the scope variable, but it is not getting displayed in the HTML page.
Please check the code that I have written below, and help me fixing the issue.
Thanks in advance.
HTML code:
<!DOCTYPE html>
<html>
<head>
<title>:: View Logs ::</title>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular.min.js"></script>
<!--<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>-->
<script src="Scripts/logsController.js"></script>
<script src="Scripts/jquery-2.1.1.js"></script>
<script src="Scripts/jquery-2.1.1.min.js"></script>
<!--<script>
ViewLogsApp = angular.module('ViewLogsApp', []);
ViewLogsApp.controller('ViewLogsController', function ($scope, $http) {
$http.get('data.json').success(function (response) {
$scope.myData = response;
});
});
</script>-->
</head>
<body>
<div ng-app="ViewLogsApp">
<div ng-controller="ViewLogsController">
<table class="table table-striped">
<tr>
<th>Log ID</th>
<th>User Type</th>
<th>User Name</th>
<th>Email ID</th>
<th>Action Type</th>
<th>Section Name</th>
<th>Section Details</th>
<th>DateTime</th>
<th>User IP</th>
</tr>
<tr ng-repeat="item in logslist">
<td>{{item.LogID}}</td>
<td>{{item.UserType}}</td>
<td>{{item.UserName}}</td>
<td>{{item.EmailID}}</td>
<td>{{item.ActionType}}</td>
<td>{{item.SectionName}}</td>
<td>{{item.SectionDetails}}</td>
<td>{{item.DateTime}}</td>
<td>{{item.UserIP}}</td>
</tr>
</table>
</div>
</div>
</body>
</html>
logsController.js code:
angular.module('ViewLogsApp', [])
.controller('ViewLogsController', [
'$scope', function ($scope) {
$scope.logslist = [];
$scope.load;
$scope.load = function () {
$.ajax({
type: 'GET',
contentType: 'application/json; charset=utf-8',
url: 'UserActivityLogs.aspx/getList',
success: function (data) {
$scope.logslist = data
$scope.$apply();
}
});
}
$scope.load();
}
]);
WebMethod code:
[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static List<UserActivityLogsList> getList()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = _connstr;
con.Open();
var logs = new List<UserActivityLogsList>();
string get = "select * from UserActivityLogs";
//string get = "sp_employee";
SqlCommand cmd = new SqlCommand(get, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
UserActivityLogsList e = new UserActivityLogsList();
e.LogID = Convert.ToInt32(dr[0]);
e.UserType = Convert.ToString(dr[1]);
e.UserName = Convert.ToString(dr[2]);
e.EmailID = Convert.ToString(dr[3]);
e.ActionType = Convert.ToString(dr[4]);
e.SectionName = Convert.ToString(dr[4]);
e.SectionDetails = Convert.ToString(dr[4]);
e.DateTime = Convert.ToString(dr[4]);
e.UserIP = Convert.ToString(dr[4]);
logs.Add(e);
}
con.Close();
return logs;
}
Clouds come floating into my life, no longer to carry rain or usher storm, but to add color to my sunset sky. ~Rabindranath Tagore
|
|
|
|
|
I have applied following css to dropdownlist.In chrome browser applied css are reflecting but in mozilla css are not reflecting. I also want to do text of dropdownlist in center align so how to do this? Please anyone guide me?
css are as follows..
border-color:blue;
border-width:2px;
border-top-left-radius:10px;
border-top-right-radius:10px;
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
-moz-border-radius-bottomleft:10px;
-moz-border-radius-bottomright:10px;
-moz-border-radius-topleft:10px;
-moz-border-radius-topright:10px;
-moz-border-radius:10px;
-webkit-box-align:center;
text-align:center;
|
|
|
|
|
|
|
Hi all,
I have a question regarding hiding of a label and a textbox on a page based on AD group membership (I only want members of the AD group to view and use the ASP control)
So I have the following within my Page_Load Sub
Dim ITContactLabel As Label = DirectCast(FormView1.FindControl("ITContactLabel"), Label)
Dim ITContactTextBox As TextBox = DirectCast(FormView1.FindControl("PRJ_ITContactTextBox"), TextBox)
If (User.IsInRole("MyDomain\My_AD_Group_X") <> "true") Then
' hide the ITContact label
ITContactLabel.Style("visibility") = "hidden"
ITContactTextBox.Visible = "false"
End If
And it works fine when the page is first loaded, but after I hit the update link, the label and textbox become visible.
I have tried to define an OnClick event in my code, but not having success hiding the label and textbox:
Protected Sub UpdateButton_Click(sender As Object, e As System.EventArgs)
in html:
<asp:linkbutton id="UpdateButton" runat="server" causesvalidation="True" onclick="UpdateButton_Click" commandname="Update" text="Update">
I'm thinking it may have something to do with checking the AD group membership, but not sure, any help would be appreciated.
|
|
|
|
|
Try moving that code to FormView1.DataBound Event. If it does not solve your issue post your entire page_load function and your UpdateButton_OnClick event.
|
|
|
|
|
this is all of my code behind:
Partial Class MyPage
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
hiddenID.Value = Convert.ToInt16(Request.QueryString("id"))
Dim LoginLabel As Label = DirectCast(FormView1.FindControl("CurrentUserLogin"), Label)
LoginLabel.Text = HttpContext.Current.User.Identity.Name
If (User.IsInRole("MYDOMAIN\MyADGroup1") <> "true") Then
Response.Redirect("~/AccessDenied.aspx")
End If
Dim ITContactLabel As Label = DirectCast(FormView1.FindControl("ITContactLabel"), Label)
Dim ITContactTextBox As TextBox = DirectCast(FormView1.FindControl("PRJ_ITContactTextBox"), TextBox)
If (User.IsInRole("MYDOMAIN\MyADGroup_X") <> "true") Then
' hide the ITContact label
ITContactLabel.Style("visibility") = "hidden"
ITContactTextBox.Visible = "false"
End If
End Sub
Protected Sub UpdateButton_Click(sender As Object, e As System.EventArgs)
Dim ITContactLabel As Label = DirectCast(FormView1.FindControl("ITContactLabel"), Label)
Dim ITContactTextBox As TextBox = DirectCast(FormView1.FindControl("PRJ_ITContactTextBox"), TextBox)
If (User.IsInRole("MYDOMAIN\MyADGroup_X") <> "true") Then
ITContactLabel.Style("visibility") = "hidden"
ITContactTextBox.Visible = "false"
End If
End Sub
End Class
|
|
|
|
|
Debug the code. Put a breakpoint in your Page_Load and see what is happening. You may have your code inside of a check for IsPostBack and so it only runs the one time.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi,
I was able to solve my issue.
string value = DataBinder.Eval(e.Row.DataItem, "SAPLeader").ToString();
dd.SelectedValue = value;
dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText(value.ToString()));
This is the fixed.
modified 29-Jul-15 13:55pm.
|
|
|
|
|
dd.Text? Shouldn't you use dd.SelectedValue or dd.SelectedItem?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
I changed it to dd.SelectedValue = value;
It still doesn't work. The issue is that once I select EDIT the current value in the SAPLeader field goes away and the dropdownlist is now showing the first value and that is the one it choses when you select UPDATE. What I would like it do is to select the right dropdown value when the dropdownlist loads.
|
|
|
|
|
try something LIKE:
ddlData.SelectedIndex=ddlData.Items.IndexOf(ddlData.Items.FindByText("value"));
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Automatically send emails at specific date time using asp.net
|
|
|
|
|
You will need to create a Windows service to send out your scheduled emails or task the windows service to call a page from you website that will trigger the sending.
|
|
|
|
|
|
Scott Hanselman has several suggestions for you:
How to run Background Tasks in ASP.NET[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Nice link. Helps me even out!
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
I have Using DevExpress Version 12 I have problem on ASPxGridview on Row selection in Keyboard Up-Down KeyBoard.I Have Set Property "KeyBoardSupport" is "True" It Display On Page load ASPxGridView First row Selected with BackColor is Black.I want first Row Is Select On Mouse Click Then Keyboard Up-Down Arrow Key Row Selction Changed.How?
|
|
|
|
|
|
I am investigating a CSRF finding in asp.net c# code behind as shown in the following code:
LinkButton LinkButtonControl = new LinkButton();
LinkButtonControl.ID = Name;
<pre>
Now, I feel that the following code using ViewStateUserKey is the right approach:
<pre>
protected override OnInit(EventArgs e) {
base.OnInit(e);
if (User.Identity.IsAuthenticated)
ViewStateUserKey = Session.SessionID; }
<pre>
However; another person I work with thinks that the Httputility.htmlencode method is the best way to correct the problem. First I don't know if the Httputility.htmlencode method is the best way and if so I would I use it?
|
|
|
|
|
|
The HtmlEncode method is one of a group of methods used to prevent XSS (Cross-Site Scripting)[^] - that's where you take input from the user and write it to the output without properly encoding it. The method provides zero protection from a CSRF vulnerability.
CSRF (aka XSRF) is a Cross-Site Request Forgery[^] vulnerability. That's where a script on another site can force the user's browser to make an authenticated request to your site without the user's knowledge. It looks like Anil has already given you some good links for dealing with this class of vulnerability.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to make one schedule in global.asax page that update date in database if current date is greater then database date. this schedule is run after every 24 hours. I have performed one task for it.
private static void Task()
{
String CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
DateTime Newdate;
DateTime dt;
SqlCommand cmd1 = new SqlCommand("select Date from tblInsertDate", con);
cmd1.ExecuteNonQuery();
List<String> dates = new List<String>();
using (SqlDataReader rdr = cmd1.ExecuteReader())
{
while (rdr.Read())
{
dt = DateTime.ParseExact(rdr["Date"].ToString(), "dd/MM/yyyy", null);
String cd = DateTime.Now.ToString("dd/MM/yyyy");
DateTime CD = DateTime.ParseExact(cd, "dd/MM/yyyy", CultureInfo.InvariantCulture);
int result = DateTime.Compare(dt, CD);
if (result < 0)
{
Newdate = dt.AddDays(7);
DateTime Newdateonly = Newdate.Date;
String Ndate = Newdateonly.ToString("dd/MM/yyyy");
dates.Add(Ndate);
break;
}
}
}
foreach (String dataList in dates)
{
SqlCommand cmd2 = new SqlCommand("update tblInsertDate set Date=@Newdate where Date=@whereDate", con);
cmd2.Parameters.AddWithValue("@Newdate", dataList);
cmd2.Parameters.AddWithValue("@whereDate",dt);
cmd2.ExecuteNonQuery();
}
}
}
all the value of database table is changed. I just want to update date row by row if current date is grater then databse date.
So I have to put one where condition in foreach loop but how to put where condition?
if i try to write
SqlCommand cmd2 = new SqlCommand("update tblInsertDate set Date=@Newdate where Date=@whereDate", con);
cmd2.Parameters.AddWithValue("@Newdate", dataList);
cmd2.Parameters.AddWithValue("@whereDate",dt);
then "dt" is not use as local variable.
|
|
|
|
|
Why are you converting all of your dates to strings, and then parsing them back to dates? Just use them as dates:
dt = DateTime.ParseExact(rdr["Date"].ToString(), "dd/MM/yyyy", null);
dt = rdr.Field<DateTime>("Date");
String cd = DateTime.Now.ToString("dd/MM/yyyy");
DateTime CD = DateTime.ParseExact(cd, "dd/MM/yyyy", CultureInfo.InvariantCulture);
DateTime CD = DateTime.Today;
List<String> dates = new List<String>();
...
Newdate = dt.AddDays(7);
DateTime Newdateonly = Newdate.Date;
String Ndate = Newdateonly.ToString("dd/MM/yyyy");
dates.Add(Ndate);
List<DateTime> dates = new List<DateTime>();
...
dates.Add(dt.AddDays(7).Date);
Having said that, you can replace all of your code with a single query:
private static void Task()
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
using (SqlCommand cmd = new SqlCommand("UPDATE tblInsertDate SET [Date] = DateAdd(day, 7, [Date]) WHERE [Date] < @Today", con))
{
cmd.Parameters.AddWithValue("@Today", DateTime.Today);
con.Open();
cmd.ExecuteNonQuery();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I created a website but it was built with the wrong code from TFS. Because of this I copy the correct code web folder from my c: drive to the IIS website folder. The website runs fine; however, when I try to build the site in VS I get the following error:
Error 102 The configSource file 'appSettings.config' is also used in a parent, this is not allowed.
|
|
|
|