Populate HTML Table with a DataTable - c#

Sorry in advance if this question seems strange or obvious but I am a very new to c#.
I'm making a web application with C# in visual studio, and I have an html table. I'd like to populate it with a table from sql server.
Here is my HTML Table:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="MRAApplication.test" %>
<!DOCTYPE html>
<body>
<form runat="server">
<asp:Button ID="populateButton" runat="server" Text="Table" onClick="populateButton_Click" />
</form>
<table id="table1">
<thead>
<tr>
<th>AlertID</th>
<th>AccountID</th>
<th>Alert</th>
<th>Active</th>
<th>IsShow</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
And when I click the button I'd like the table to be filled with a datatable that I'm creating here:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
namespace MRAApplication
{
public partial class test : System.Web.UI.Page
{
protected void populateButton_Click(object sender, EventArgs e)
{
GetDataTable();
}
public static System.Data.DataTable GetDataTable()
{
string queryString = "Select * FROM Alerts";
string conn = ConfigurationManager.ConnectionStrings["UATConnectionString"].ToString();
SqlDataAdapter adapter = new SqlDataAdapter(queryString, conn);
System.Data.DataTable dt = new System.Data.DataTable();
dt.TableName = "Table";
using (System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(queryString, conn))
{
da.Fill(dt);
}
return dt;
}
}
}
The UATConnectionString is working (I'm almost positive), so now I just need to get the data from the SQLtable I'm connecting to into the HTMLtable.
If anybody could help me I would appreciate it. If there is any more information needed I will be glad to help.

You should use Repeater Control for this.
You can see a very good example here:
http://msdn.microsoft.com/en-us/library/zzx23804(v=vs.85).aspx

Related

Crystal Report on ASP C# application & postback issues

I have a webform with a single button and one crystal report viewer. Crystal report is based on a MS SQL stored procedure & designed using a connection that uses SQL Server authentication.
What I have noticed that, if I call the method for showing the report within the page load, my crystal repot loads perfectly. However, if I trigger the report load through the button click (Which is a must for me to accept parameters for the report at deployment) the below happens:
Crystal report parameters are prompted (Which doesn't occur when report is loaded without a postback).
After the 1st page being loaded, 2nd page navigation prompts for database login. Without providing the login details (usually the password only), cannot go ahead. This logon prompt is only applicable to 2nd page of the report.
To circumvent the situation, I created a new connection with integrated security & postback stopped asking for the parameters and database login. Unfortunately, I cannot use integrated security for deploying the application & pry for a proper solution or workaround.
Fearing the worst, I already have RDLC report designed with the same requirements, however, I see that I have better formatting options like drawing lines over the sub reports to split columns when Crystal Report is used.
Here is what I have I tried until now
ASP page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="c2.aspx.cs" Inherits="CrystalTest.c2" %>
<%# Register Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Show Report" OnClick="Button1_Click" />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="False" GroupTreeImagesFolderUrl="" Height="1202px" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" ToolPanelView="None" ToolPanelWidth="200px" Width="1104px" />
</div>
</form>
</body>
</html>
Code behind
using CrystalDecisions.CrystalReports.Engine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CrystalTest
{
public partial class c2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//ShowReport();
}
private void ShowReport()
{
ReportDocument oRpt = new ReportDocument();
oRpt.Load(Server.MapPath(#"~/CrystalReport2.rpt"));
oRpt.SetParameterValue(0, 2020);
oRpt.SetParameterValue(1, 1);
oRpt.SetParameterValue(2, "3");
oRpt.SetParameterValue(3, "1");
oRpt.SetParameterValue(4, "1");
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.ReportSource = oRpt;
//oRpt.SetDatabaseLogon("sa", "password", "RT04", "menass");
oRpt.DataSourceConnections[0].SetConnection("RT04", "menass", true);
}
protected void Button1_Click(object sender, EventArgs e)
{
ShowReport();
}
}
}
I have referred the following threads from different websites and was able develop a simple solution.
1.https://www.c-sharpcorner.com/forums/crystal-reports-asking-for-database-login-credentials
2.https://forums.asp.net/post/1797759.aspx
All I needed was to pass the logon information back to the report viewer once after POSTBACK happens. Example as below:
ASP Page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="c3.aspx.cs" Inherits="CrystalTest.c3" %>
<%# Register Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Print Button" OnClick="Button1_Click" />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="false" />
</div>
</form>
</body>
</html>
Code Behind
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CrystalTest
{
public partial class c3 : System.Web.UI.Page
{
public ReportDocument oRpt;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
ConnectionInfo myConnectionInfo = new ConnectionInfo();
myConnectionInfo.ServerName = "RT04";
myConnectionInfo.DatabaseName = "MenaSS";
myConnectionInfo.UserID = "sa";
myConnectionInfo.Password = "password";
SetdblogonforReport(myConnectionInfo);
}
}
private void SetdblogonforReport(ConnectionInfo myConnectionInfo)
{
//throw new NotImplementedException
TableLogOnInfos mytableloginfos = new TableLogOnInfos();
mytableloginfos = CrystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
{
myTableLogOnInfo.ConnectionInfo = myConnectionInfo;
}
}
private void ShowReport()
{
if (!IsPostBack | Session["Report"] == (default))
{
oRpt = new ReportDocument();
oRpt.Load(Server.MapPath(#"~/CrystalReport2.rpt"));
oRpt.SetParameterValue(0, 2020);
oRpt.SetParameterValue(1, 1);
oRpt.SetParameterValue(2, "9");
oRpt.SetParameterValue(3, "1");
oRpt.SetParameterValue(4, "1");
Session.Add("Report", oRpt);
}
else
{
oRpt = (ReportDocument)Session["Report"];
}
CrystalReportViewer1.ReportSource = oRpt;
oRpt.SetDatabaseLogon("sa", "password", "RT04", "menass");
}
protected void Button1_Click(object sender, EventArgs e)
{
ShowReport();
}
}
}
This solution is good enough for sub reports also, as all the authentications are taken care by the single logon call using the method SetdblogonforReport.
Hope this helps few others out there.
I've a better solution & not deleting the previous one because it does deal with the postback when page_load method is present in a page. The below answer (which is recommended by SAP) is the one I am currently using for my project.
Resolving this requirement using "Session" and "page_init" as suggested. Please note, my application need to collect many inputs from the end user before generating the report & many of the text inputs have Autopostback set as true. Everytime the autopostback happens, Crystal Report refreshes, hence I recommend using as less possible Autopostback enabled input fields with your web form.
Sample ASP page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="c4.aspx.cs" Inherits="CrystalTest.c4" %>
<%# Register Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Print Report" OnClick="Button1_Click" />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
</html>
and the code behind (copied from a crude test form, please make sure that you follow the coding standards recommended). Please note, this sample doesn't have "page_load" method, hence if you have specific situations where page_load is required, you will have to adapt much tedious approaches or clicking the button to generate the report should be redirected to a page where you have only the report.
using CrystalDecisions.CrystalReports.Engine;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CrystalTest
{
public partial class c4 : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
if (IsPostBack)
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["Report"];
}
}
private void ShowReport1()
{
string ConnectionString = ConfigurationManager.ConnectionStrings["menass"].ToString();
using (SqlConnection con = new SqlConnection(ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("GETMONTHSALARY", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#pProcessYear", SqlDbType.Int).Value = 2020;
cmd.Parameters.Add("#pProcessMonth", SqlDbType.Int).Value = 1;
cmd.Parameters.Add("#pProcessSection", SqlDbType.VarChar).Value = "9";
cmd.Parameters.Add("#pProcessSite", SqlDbType.VarChar).Value = "1";
cmd.Parameters.Add("#pProcessCatg", SqlDbType.VarChar).Value = "1";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "SalaryDT");
ReportDocument oRpt = new ReportDocument();
oRpt.Load(Server.MapPath(#"~/dataset/CrystalReport1.rpt"));
oRpt.DataSourceConnections.Clear();
oRpt.SetDataSource(ds);
oRpt.Subreports[0].SetDataSource(FillOverTime());
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.ReportSource = oRpt;
Session["Report"] = oRpt;
}
}
}
private DataSet FillOverTime()
{
string ConnectionString = ConfigurationManager.ConnectionStrings["menass"].ToString();
using (SqlConnection con = new SqlConnection(ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("GetEmployeeOverTime", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#pEmployeeCode", SqlDbType.VarChar).Value = DBNull.Value;
cmd.Parameters.Add("#pProcessYear", SqlDbType.Int).Value = 2020;
cmd.Parameters.Add("#pProcessMonth", SqlDbType.Int).Value = 1;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds1 = new DataSet();
adapter.Fill(ds1, "OverTimeDT");
return ds1;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ShowReport1();
}
}
}

autocmplete in asp.net with ajax

I am trying to autocomplete textbox, and i downloaded source code from any website,
Here is aspx page code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ajax AutoCompleteExtender without Webservice</title>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server"/>
<div>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
TargetControlID="txtCountry"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1"
CompletionInterval="1000" ServiceMethod="GetCountries" >
</ajax:AutoCompleteExtender>
</div>
</form>
and here is codebehind file.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetCountries(string prefixText)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("select varStateName from tblStateMaster where varStateName like #Name'%'", con);
cmd.Parameters.AddWithValue("#Name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<string> CountryNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CountryNames.Add(dt.Rows[i][1].ToString());
}
return CountryNames;
}
}
It could not generate proper output and i am not able to debug this service, so how can i debug such service, and please tell me where is exact problem and which points should be remember for service and autocomplete,
And one more thing can i do it with dropdownlist?
I suspect the issue is in your query and more specifically in the %, try to include it in your parameter instead:
prefixText = string.Concat(prefixText, "%");
SqlCommand cmd = new SqlCommand("select varStateName from tblStateMaster where varStateName like #Name", con);
EDIT
Ok, so digging around, according to official examples from Microsoft, your method signature should look like this (notice the additional parameters):
public static string[] GetCountries(string prefixText)
{
// your stuff
}

Generating asp controls with mark up in db [duplicate]

How do I generate the controls in a div based on the markup defined in a SQL Server database? Is it possible? If yes, then how? Can anyone give me resources?
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="lit" runat="server" ClientIDMode="Static" Mode="Transform"></asp:Literal>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection _newConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand storedProcedure = new SqlCommand("sp_getMarkup", _newConnection);
storedProcedure.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(storedProcedure);
_newConnection.Open();
da.Fill(ds);
_newConnection.Close();
DataTable dt = ds.Tables["Table"];
string s = (from str in dt.AsEnumerable()
where str.Field<int>("Id").Equals(1)
select str.Field<string>("elemMarkup")).SingleOrDefault().ToString();
this.lit.Text = s;
}
}
}
In the database I have stored string as
<asp:CheckBox ID="chk" runat="server" ClientIDMode="Static" />
Now the problem is the control is rendered on page but is not visible. I can see it in view source.
Can anyone help me?
You can use ParseControl which accepts a string and create controls on the fly.
The drawback is if server code is in the string, it will not be executed. In addition, you need to attach event manually such as button click events.
For example,
<script runat="server">
// This server code will not be executed
</script>
Here is another SO question using jquery ajax to load info from database
I would recommend having some type of sanitizing intermediary; otherwise you are opening yourself up to cross-site scripting (XSS) issues.
You could use a placeholder on a page like so:
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
And in your code behind, you could have several checks (all of which contain SQL statements querying the data in the database). The database could contain a field containing component names such as checkbox, button (various other controls). This saves you storing markup in the database fields..
Very rough representation of how the code would look like..
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// SQL Code here
// Datatable code here
// End of DataTable code
// Beginning of IF blocks
If (DataTable.Rows.Count > 0) {
If (your check != "checkbox") {
this.PlaceHolder1.Controls.Add(new Button(){
Text = "Added"}
}
}
// More if statements here
);
}
}
Alternatively if you insist on storing asp markup in the database, then you could just feed the asp markup into the placeholder using a loop (if there are more than one rows in your database)

How to generate asp.net control using markup in database

How do I generate the controls in a div based on the markup defined in a SQL Server database? Is it possible? If yes, then how? Can anyone give me resources?
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="lit" runat="server" ClientIDMode="Static" Mode="Transform"></asp:Literal>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection _newConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand storedProcedure = new SqlCommand("sp_getMarkup", _newConnection);
storedProcedure.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(storedProcedure);
_newConnection.Open();
da.Fill(ds);
_newConnection.Close();
DataTable dt = ds.Tables["Table"];
string s = (from str in dt.AsEnumerable()
where str.Field<int>("Id").Equals(1)
select str.Field<string>("elemMarkup")).SingleOrDefault().ToString();
this.lit.Text = s;
}
}
}
In the database I have stored string as
<asp:CheckBox ID="chk" runat="server" ClientIDMode="Static" />
Now the problem is the control is rendered on page but is not visible. I can see it in view source.
Can anyone help me?
You can use ParseControl which accepts a string and create controls on the fly.
The drawback is if server code is in the string, it will not be executed. In addition, you need to attach event manually such as button click events.
For example,
<script runat="server">
// This server code will not be executed
</script>
Here is another SO question using jquery ajax to load info from database
I would recommend having some type of sanitizing intermediary; otherwise you are opening yourself up to cross-site scripting (XSS) issues.
You could use a placeholder on a page like so:
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
And in your code behind, you could have several checks (all of which contain SQL statements querying the data in the database). The database could contain a field containing component names such as checkbox, button (various other controls). This saves you storing markup in the database fields..
Very rough representation of how the code would look like..
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// SQL Code here
// Datatable code here
// End of DataTable code
// Beginning of IF blocks
If (DataTable.Rows.Count > 0) {
If (your check != "checkbox") {
this.PlaceHolder1.Controls.Add(new Button(){
Text = "Added"}
}
}
// More if statements here
);
}
}
Alternatively if you insist on storing asp markup in the database, then you could just feed the asp markup into the placeholder using a loop (if there are more than one rows in your database)

ASP Button onClick to send data from text box to database

I'm new to ASP.
I am trying to insert data from an asp:textbox into a SQL Server database.
I have created a class in the APP_CODE folder which handles the database connection and insert methods.
When button1 is clicked I want it to take the data from the asp:textbox and use the questionnaireSQL.cs file in APP_CODE to update the database.
How can I go about this?
questionnaireSQL.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace Devworks
{
public class OscarSQL
{
private string _productConnectionString;
private SqlConnection _productConn;
public OscarSQL()
{
_productConn = new SqlConnection();
_productConnectionString += "data source=mssql.dev-works.co.uk; Initial Catalog=devworks_oscar;User ID=myusername;Password=mypassword";
_productConn.ConnectionString = _productConnectionString;
}
// Insert New Questionnaire:
public int InsertQuestionnaire(string QuestName, int CustomerID, int NumberOfQuest)
{
int retVal = 0;
SqlCommand myCommand = new SqlCommand("NewQuestionnaire", _productConn);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new SqlParameter("#QUESTNAME", SqlDbType.NVarChar));
myCommand.Parameters.Add(new SqlParameter("#CUSTID", SqlDbType.Int));
myCommand.Parameters.Add(new SqlParameter("#NUMQUEST", SqlDbType.Int));
myCommand.Parameters.Add("#QUEST_ID", SqlDbType.Int, 0, "QUEST_ID");
myCommand.Parameters["#QUEST_ID"].Direction = ParameterDirection.Output;
myCommand.Parameters[0].Value = QuestName;
myCommand.Parameters[1].Value = CustomerID;
myCommand.Parameters[2].Value = NumberOfQuest;
_productConn.Open();
myCommand.ExecuteNonQuery();
retVal = (int)myCommand.Parameters["#QUEST_ID"].Value;
_productConn.Close();
return retVal;
}
// SQL DATAREADER, DATATABLE & NON QUERY UPDATE:
private void insert(SqlCommand myCommand)
{
_productConn.Open();
myCommand.ExecuteNonQuery();
_productConn.Close();
}
private SqlDataReader getData(SqlCommand myCommand)
{
_productConn.Open();
SqlDataReader myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
return myDataReader;
}
private DataTable createDataTable(SqlDataReader data)
{
DataTable retVal = new DataTable();
retVal.Load(data);
return retVal;
}
}
}
newquestionnaire.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="new_questionnaire.aspx.cs" Inherits="new_questionnaire" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container">
<div class="main">
<h2 class="new">Add Your Questionnaire</h2>
<h3>Give your questionnaire a name.</h3>
<asp:TextBox ID="QuestName" runat="server"></asp:TextBox>
<h3>CustomerID</h3>
<asp:TextBox ID="CustomerID" runat="server"></asp:TextBox>
<h3>Number Of Questions</h3>
<asp:TextBox ID="NumberOfQuest" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Create" />
</div> <!-- end main -->
</div> <!-- end container -->
</asp:Content>
newquestionnaire.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Devworks;
public partial class new_questionnaire : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
Thanks in advance
You've posted all this code but exactly what can't you do?
One has to wonder if you wrote the DAL (Data access layer - your db code) and the Web UI, how is it that you cannot write the click event of a button ironically called Button1 ??
You take the value of your textbox and on the click of a button insert it into a database.
When you have a large task seperate it into smaller ones and do each piece until you've finished the puzzle.
According to your code
OscarSQL c = new OscarSQL(); //btw: not sure why you are not using a static class for this
int result = c.InsertQuestionnaire(textBox.Text ...); //add all parameters here
If (result > 0)
//good id
else
//display error message
Place all of this code behind the button1_click event of your code.

Categories