Saturday, November 24, 2018
Tuesday, August 1, 2017
Implement Google Column Stack Charts With Link integration
Please find the following code.
<!DOCTYPE html>
<html lang="en-US">
<body>
<h1>My Web Page</h1>
<div id="piechart" style="width:80%;height:600px;"></div>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Division', 'Compliances','link', 'Non Compliances'],
['ILTD', 500,'http://en.wikipedia.org/wiki/2003', 100],
['PSPD', 682,'http://en.wikipedia.org/wiki/2004', 200],
['LRBD', 1874,'http://en.wikipedia.org/wiki/2005', 180],
['ESPB', 1324,'http://en.wikipedia.org/wiki/2006', 99],
['CORP', 457,'http://en.wikipedia.org/wiki/2007', 56],
['PSPB', 1598,'http://en.wikipedia.org/wiki/2008', 45]
]);
var view = new google.visualization.DataView(data);
view.setColumns([0,1,3]);
var options = {
title: 'Summary Report',
/*width:600, height:400,
vAxis: {title: "Year"},
hAxis: {title: "Cups"}*/
legend: { position: 'bottom', maxLines: 3 },
isStacked: true,
series: {
0: { color: '#109618' },
1: { color: '#dc3912' }
}
};
var chart = new google.visualization.ColumnChart(
document.getElementById('piechart'));
chart.draw(view, options);
var selectHandler = function(e) {
window.location = data.getValue(chart.getSelection()[0]['row'], 2 );
}
google.visualization.events.addListener(chart, 'select', selectHandler);
}
</script>
</body>
</html>Tuesday, September 27, 2016
Export ASPX GridView control to Excel
GridView control in aspx page
Report.aspx
<asp:Button ID="btnExport" runat="server" Text="Export To Excel" OnClick ="btnExport_Click" />
<br /><br />
<asp:GridView ID="GridView1" PageSize="5" AllowPaging="True" DataKeyField="PSID" OnRowDataBound="RowDataBound" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundField DataField="PSID" HeaderText="PSID" SortExpression="PSID"></asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name"></asp:BoundField>
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email"></asp:BoundField>
<asp:BoundField DataField="Area" HeaderText="Area" SortExpression="Area"></asp:BoundField>
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department"></asp:BoundField>
<asp:BoundField DataField="Attempted" HeaderText="No of Attemped" SortExpression="Attempted"></asp:BoundField>
<asp:BoundField DataField="AcceptedStatus" HeaderText="Status" SortExpression="AcceptedStatus"></asp:BoundField>
</Columns>
</asp:GridView>
Report.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(conString))
{
if(!IsPostBack){
Status.Items.Add(new ListItem("All Status", ""));
Status.Items.Add(new ListItem("Accepted", "1"));
Status.Items.Add(new ListItem("Decline", "0"));
}
using (SqlCommand cmd = new SqlCommand("SELECT * FROM TBL_TRN_REPORT", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
protected void btnExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xlsx");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
//It solves the error "Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
}
Report.aspx
<asp:Button ID="btnExport" runat="server" Text="Export To Excel" OnClick ="btnExport_Click" />
<br /><br />
<asp:GridView ID="GridView1" PageSize="5" AllowPaging="True" DataKeyField="PSID" OnRowDataBound="RowDataBound" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundField DataField="PSID" HeaderText="PSID" SortExpression="PSID"></asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name"></asp:BoundField>
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email"></asp:BoundField>
<asp:BoundField DataField="Area" HeaderText="Area" SortExpression="Area"></asp:BoundField>
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department"></asp:BoundField>
<asp:BoundField DataField="Attempted" HeaderText="No of Attemped" SortExpression="Attempted"></asp:BoundField>
<asp:BoundField DataField="AcceptedStatus" HeaderText="Status" SortExpression="AcceptedStatus"></asp:BoundField>
</Columns>
</asp:GridView>
Report.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(conString))
{
if(!IsPostBack){
Status.Items.Add(new ListItem("All Status", ""));
Status.Items.Add(new ListItem("Accepted", "1"));
Status.Items.Add(new ListItem("Decline", "0"));
}
using (SqlCommand cmd = new SqlCommand("SELECT * FROM TBL_TRN_REPORT", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
protected void btnExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xlsx");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
//It solves the error "Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
}
Friday, January 1, 2016
Ajax Call from Web form application
Hi,
I had a problem while i trying to submit variable value with dynamic button control.
The example was like
I had a problem while i trying to submit variable value with dynamic button control.
The example was like
<% foreach(int productId in products){ %><asp:Button ID="Button2" onclick="callfunction" CommandArgument="<%= productId %>" runat="server" Text="Button" /><% }?>But i found it's not working because of control value will not assign after page_load. Then i try to do it with AJAXI have change the Button control with HTML Button<% foreach(int productId in products){ %> <input id="Button1" onclick="AddtoCartItems(<%=product.ProductId %>)" type="button" value="Add To Cart" /> <% }?>After that i have written the following ajax code.<script type="text/javascript">
function AddtoCartItems(pid) {
$.ajax({
url: 'AddToCart.aspx/GetData',
type: "POST",
dataType: "json",
data: "{'name': '" + pid + "'}",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(JSON.stringify(data));
}
});
}
</script>Now i have create AddToCart.aspx With GetData Methord
using System.Web.Services;
using Newtonsoft.Json;
[WebMethod]
public static string GetData(string name)
{
--------Your code here----------- return "Success";
}2 more thing you need to do.Go to App_Start/RouteConfig.cs Change settings.AutoRedirectMode = RedirectMode.Permanent; TOsettings.AutoRedirectMode = RedirectMode.Off; Same As go to Web.config and add the following line<system.web> ... <webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<authorization>
<allow users="*"/>
</authorization>
</system.web> That's it. Now you can call your AJAX method successfully. Monday, December 28, 2015
Date time discussion
Finally i found how to convert time stamp to Date & Date to time stamp
. I found some places in project people keep date as time stamp for get
difference quickly. so in this case they use to keep the table column
as Int or time stamp. now the problem is that in the application while
showing the data, you need to convert it into date variable. So for that
we can use the following code to convert time stamp to Date
In the second case if you want to convert Date to time stamp then check the following code.
If you want to convert string to date find the following code.
DateTime dt = Convert.ToDateTime("2015-12-13");
int ts = 1451174400;
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(ts).ToLocalTime();
string formattedDate = dt.ToString("dd-MM-yyyy");
Now you can get any date format from this variable.In the second case if you want to convert Date to time stamp then check the following code.
int ts = (dt.Ticks - 621356166000000000) / 10000000;
Where dt is the date time variable & holding a date value.If you want to convert string to date find the following code.
DateTime dt = Convert.ToDateTime("2015-12-13");
Saturday, October 24, 2015
SSRS Series Part using SQL Server Biseness intelligence
This tutorial is just wonderful if you are learning SSRS report firs time.
This will tell you how to create report -> deploy -> integrate with your aspx application.
http://www.codeproject.com/Articles/194097/SSRS-Series-Part-I-Various-ways-of-Report-creation
This will tell you how to create report -> deploy -> integrate with your aspx application.
http://www.codeproject.com/Articles/194097/SSRS-Series-Part-I-Various-ways-of-Report-creation
Friday, October 23, 2015
ASP.NET - Single-Page Applications with MVVM Patterns
Hello friends i have found the following tutorial. This is very useful tutorial to know
Single-Page Applications with MVVM Patterns
https://msdn.microsoft.com/en-us/magazine/dn463786.aspx
Single-Page Applications with MVVM Patterns
https://msdn.microsoft.com/en-us/magazine/dn463786.aspx
Reporting Services permissions on SQL Server
I got this error while i tried to execute report server.
(ser does not have required permissions. Verify that sufficient permissions have been granted and Windows User Account Control (UAC) restrictions have been addressed)
(ser does not have required permissions. Verify that sufficient permissions have been granted and Windows User Account Control (UAC) restrictions have been addressed)
- Configure the report server for local administration. To access the report server and Report Manager locally, follow these steps:
- Start Windows Internet Explorer.
- On the Tools menu, click Internet Options.
- Click Security.
- Click Trusted Sites.
- Click Sites.
- Under Add this Web site to the zone, type http://<var>ServerName</var>. If you are not using HTTPS for the default site, click to clear the Require server certification (https:) for all sites in this zone check box.
- Click Add.
- Repeat step 7f and step 7g to add the http://localhost URL, and then click Close.
- Note This step enables you to start Internet Explorer and open either the localhost or the network computer name of the server for both the Report Server application and the Report Manager application.
- Create role assignments that explicitly grant you access together with full permissions. To do this, follow these steps:
- Start Internet Explorer together with the Run as administrator option. To do this, click Start, click All Programs, right-click Internet Explorer, and then click Run as administrator.
- Open Report Manager. By default, the Report Manager URL is http://<var>ServerName</var>/reports.
If you use SQL Server Express with Advanced Services SP2, the Report Manager URL is http://<var>ServerName</var>/reports$sqlexpress. If you use a named instance of Reporting Services, the Report Manager URL is http://<var>ServerName</var>/reports$<var>InstanceName</var> - In the Home dialog box, click Properties.
- Click New Role Assignment.
- Type a Windows user account name by using the following format:
<var>Domain</var>\<var>User</var>
- Click to select the Content Manager check box.
- Click OK.
- In the Home dialog box, click Site Settings.
- Click Configure site-wide security.
- Click New Role Assignment.
- Type a Windows user account by using the following format:
<var>Domain</var>\<var>User</var>
- Click System Administrator.
- Click OK.
- Close Report Manager.
- Use Internet Explorer without the Run as administrator option to reopen Report Manager.
The request failed with HTTP status 401: Unauthorized
I even tried this solution
1. Click Start, click Run, type regedit, and then click OK.
2. In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
3. Right-click Lsa, point to New, and then click DWORD Value.
4. Type DisableLoopbackCheck, and then press ENTER.
5. Right-click DisableLoopbackCheck, and then click Modify.
6. In the Value data box, type 1, and then click OK.
7. Quit Registry Editor, and then restart your computer.
but it still not working.
Tuesday, April 28, 2015
DataGridView Implementation with DataSet
DataGridView Implementation with DataSet
SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["studentConnectionString"].ConnectionString);
string sql = "SELECT * FROM student";
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "student");
connection.Close();
dataGridView1.DataSource = ds;
// dataGridView1.DataMember = "student"; //DataMember -- if the DataSet content More than one table then binding the particular table with grid we use this
dataGridView1.DataBind();
string sql = "SELECT * FROM student";
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "student");
connection.Close();
dataGridView1.DataSource = ds;
// dataGridView1.DataMember = "student"; //DataMember -- if the DataSet content More than one table then binding the particular table with grid we use this
dataGridView1.DataBind();
Wednesday, April 22, 2015
Insert in DB C# Dot Net
Please find the following code for connecting with DB
SqlConnection connection = new SqlConnection("Data Source=MACK;Initial Catalog=student;User ID=sa;Password=sourav321");
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "insert into student(id, username, password, name, email) values(@id, @uname, @password, @name, @email)";
command.Parameters.Add("@uname", UserName.Text);
command.Parameters.Add("@password", Password.Text);
command.Parameters.Add("@name", Name.Text);
command.Parameters.Add("@email", Email.Text);
command.Parameters.Add("@id", Guid.NewGuid().ToString());
connection.Open();
command.ExecuteNonQuery();
connection.Close();
SqlConnection connection = new SqlConnection("Data Source=MACK;Initial Catalog=student;User ID=sa;Password=sourav321");
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "insert into student(id, username, password, name, email) values(@id, @uname, @password, @name, @email)";
command.Parameters.Add("@uname", UserName.Text);
command.Parameters.Add("@password", Password.Text);
command.Parameters.Add("@name", Name.Text);
command.Parameters.Add("@email", Email.Text);
command.Parameters.Add("@id", Guid.NewGuid().ToString());
connection.Open();
command.ExecuteNonQuery();
connection.Close();
Subscribe to:
Posts (Atom)
