|
Karthick_gc wrote: What is the use of Ajax concept in Asp.net? can anyone explain?
Yes. Check here[^]
and
Read This[^]
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
Hi ,
Ihave a datagrid ,and the code for the date field is some what
<asp:BoundColumn DataField="RegistrationDate" HeaderText="Reg Date" SortExpression="RegistrationDate" DataFormatString="{0:yyyy/mmm/dd}">
<HeaderStyle Font-Bold="True" Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
but the date is not comming in the yyyy/mmm/dd format
in the datagrid i enabled the sorting and i am using the following code for that
DataSet ds = CandidateManager.getCandidateDetails(cboStatus.SelectedValue, cboLocation.SelectedItem.Text.Trim(),cboType.SelectedItem.Text.Trim(),txtName.Text.Trim(),txtCurrentOrg.Text.Trim(),txtRegFromDate.Text.Trim(),txtRegToDate.Text.Trim(),m_summaryDetails);
DataView Source = ds.Tables["CANDIDATE_MASTER"].DefaultView;
Source.Sort = e.SortExpression;
Session["Candidate_Sort"] = e.SortExpression;
DGInbox.DataSource = Source;
DGInbox.DataBind();
But the sorting is not happening properly.
It is happening acoording to the month only.
(Actually i want to get the date in yyyy/mmm/dd format
,but getting mmm/dd/yyyy format,and sorting is
happening with month only)
|
|
|
|
|
Your format string isn't quite correct. I don't remember them all, but I know that month is a capital 'M', lowercase 'm' is minute.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
//file1.aspx
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" />
<br />
<br />
<asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px"
style="background-color: #00cccc"></asp:Label><br />
<br />
<asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand"
style="Z-INDEX: 101; LEFT: 175px; TOP: 105px"
runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" >
<Columns>
<asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit">
</asp:ButtonColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete">
</asp:ButtonColumn>
</Columns>
</asp:DataGrid><br />
</div>
</form>
</body>
//file1.aspx.cs
public partial class _Default : System.Web.UI.Page
{
OracleConnection cn;
OracleCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
cn = new OracleConnection("data source=dev;user id=hr;password=hr");
if (!Page.IsPostBack)
{
BindData();
}
}
void BindData()
{
string strsql = "select job_id,job_title from jobs";
OracleDataAdapter da = new OracleDataAdapter(strsql, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text);
lblMessage.Text = "";
}
if (e.CommandName == "Delete")
{
lblMessage.Text = "Need Code to call confirm() frunction ";
}
}
void FillTheData(string job_id, string job_title)
{
TxtJobID.Text = job_id;
TxtJobTitle.Text = job_title;
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string strsql = "Update jobs set job_title="+"'"+TxtJobTitle.Text+"'"+" where job_id="+"'"+TxtJobID.Text+"'";
cmd = new OracleCommand(strsql, cn);
cn.Open();
cmd.ExecuteNonQuery();
BindData();
lblMessage.Text = "Updated Successfully";
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
finally
{
cn.Close();
}
}
}
|
|
|
|
|
define your problem rather then code? put your question first and then put the code.
|
|
|
|
|
the problem is that i want to add confirmation from the user to delete the record when the delete button is pressed in the grid.
i have the code to delete the record. Just need help how to call the cofirm() javascript function.
and what changes should i make in the code to call the function
//file1.aspx
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TxtJobID" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtJobTitle" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Update" OnClientClick="return confirm('Are You Sure');" Font-Bold="True" />
<br />
<br />
<asp:Label ID="lblMessage" runat="server" Text="Label" Width="474px"
style="background-color: #00cccc"></asp:Label><br />
<br />
<asp:DataGrid id="DataGrid1" OnItemCommand="ItemCommand"
style="Z-INDEX: 101; LEFT: 175px; TOP: 105px"
runat="server" CssClass="tx-tbl-Gr-lml" Width="474px" AllowPaging="true" >
<Columns>
<asp:ButtonColumn Text="Edit" ButtonType="PushButton" CommandName="Edit">
</asp:ButtonColumn>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete">
</asp:ButtonColumn>
</Columns>
</asp:DataGrid><br />
</div>
</form>
</body>
//file1.aspx.cs
public partial class _Default : System.Web.UI.Page
{
OracleConnection cn;
OracleCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
cn = new OracleConnection("data source=dev;user id=hr;password=hr");
if (!Page.IsPostBack)
{
BindData();
}
}
void BindData()
{
string strsql = "select job_id,job_title from jobs";
OracleDataAdapter da = new OracleDataAdapter(strsql, cn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
protected void ItemCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
FillTheData(e.Item.Cells[2].Text, e.Item.Cells[3].Text);
lblMessage.Text = "";
}
if (e.CommandName == "Delete")
{
lblMessage.Text = "Need Code to call confirm() frunction ";
}
}
void FillTheData(string job_id, string job_title)
{
TxtJobID.Text = job_id;
TxtJobTitle.Text = job_title;
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string strsql = "Update jobs set job_title="+"'"+TxtJobTitle.Text+"'"+" where job_id="+"'"+TxtJobID.Text+"'";
cmd = new OracleCommand(strsql, cn);
cn.Open();
cmd.ExecuteNonQuery();
BindData();
lblMessage.Text = "Updated Successfully";
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
finally
{
cn.Close();
}
}
}
Above is the code
|
|
|
|
|
put the button between span tag.
/*
<span onclick=return confirm('Are you sure to Delete the record?')>
<asp:button id="deletelink" text="Delete" runat="server" commandargument="<%#Eval("id") commandname="deletebtn" xmlns:asp="#unknown">
</asp:button>
</span>
*/
Regards
Keyur Satyadev
modified on Thursday, March 12, 2009 8:53 AM
|
|
|
|
|
AJAX has a way to do a confirm. Pretty simple too, and an example found on the AJAX site.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hi,
You can write the javascript function for the button click....
|
|
|
|
|
protected void grd_detail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[4].Attributes.Add("onClick", "return confirm('Are you sure you want to delete the record?');");
}
}
use this code in event row data bound of grid view
|
|
|
|
|
hi all ,i am a newbie here.
recently,i need to creat a real-time responsing comment page.if client sent a comment.it will auto refuse page and display what client post in comment board.
sorry that cos my english is limited,maybe i can't describe it properly
(i have been asked the question in local forum,but there is no answer)
here is the question:
when submited,datas writed into database.
in CS file, it reture latest date "DataTable" to "get_Result_CallBack "
code here:
function get_Result_CallBack(response)
{
if (response.value != null)
{
z = 0;
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds.Rows != null)
{
arrCellText[0] = ds.Rows[0].Message+" "+ds.Rows[0].UpdateDate ;
arrCellText[1] = ds.Rows[0].Name ;
arrCellText[2] = " <a href='"+ds.Rows[0].ID+"'>REPLY </a>" ;
arrCellText[3] = " <a href='"+ds.Rows[0].ID+"'>DELETE </a>";
var resulttable= "tab"+ds.Rows[0].Img_ID;//this is Table in Datelist.i named Table "tab+meassage ID"
var resulttr= "tr"+ds.Rows[0].Img_ID;
_tab = document.getElementById(resulttable) ;
_tr = document.getElementById(resulttr) ;
createRowCell(_tab, _tr, arrCellText) ;
}
}
return
}
function createRowCell(tab, tr, arrCellText)
{
trNew = tab.insertRow(0) ;
for(var i=0; i <tr.cells.length; i++)
{
//alert(arrCellText[i]);here respones values of every field.
var tdNew = trNew.insertCell() ;
var tnNew = document.createTextNode(arrCellText[i]) ;
tdNew.appendChild(tnNew) ;
}
}
but,"Table" and the page have no any responsing.no refusing,if i press F5.result will display.
if i post in a worry catalog,or there is a better catalog.plx tell me.thanks!!!
|
|
|
|
|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml.Xsl;
using System.Text;
using System.Threading;
public class ExportToExcel
{
System.Web.UI.Page page;
System.Web.HttpResponse Response;
public ExportToExcel(System.Web.UI.Page page)
{
page = this.page;
Response = System.Web.HttpContext.Current.Response;
}
public void ExportDataToExcel(DataTable datatable, string[] Headers, string SourcePath, string DestinationPath)
{
int i, j;
string strSourceTemplate = "";
string strDestFileName = "";
string strHeaders = "";
string strRow = "";
System.Data.OleDb.OleDbConnection objXlsCon = null;
System.Data.OleDb.OleDbCommand objCmd;
try
{
objXlsCon = new System.Data.OleDb.OleDbConnection();
if (datatable.Rows.Count > 0)
{
strSourceTemplate = SourcePath;
strDestFileName = DestinationPath;
System.IO.File.Copy(strSourceTemplate, strDestFileName);
objXlsCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDestFileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;MAXSCANROWS=1;\";";
objXlsCon.Open();
objCmd = new System.Data.OleDb.OleDbCommand();
objCmd.Connection = objXlsCon;
for (i = 0; i < Headers.Length; i++)
{
strHeaders += Headers[i].ToString() + ",";
}
string s=datatable.Columns[0].ColumnName;
int k=0;
foreach (DataRow drow in datatable.Rows)
{
for (j = 0; j < datatable.Columns.Count; j++)
{
if(Headers.Length > k)
{
if(datatable.Columns[j].ColumnName == Headers[k].ToString())
{
if(drow[j].ToString() != "" )
{
strRow += drow[j].ToString() + "','";
}
else
{
strRow +="-'"+",'";
}
k++;
}
}
}
objCmd.CommandText = "Insert into [Sheet1$] (" + strHeaders.Substring(0, strHeaders.Length - 1) + ") values ('" + strRow.Substring(0, strRow.Length - 3) + "')";
objCmd.ExecuteNonQuery();
strRow = "";
j = 0;
k=0;
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
objCmd = null;
objXlsCon.Close();
}
}
public void Download(string strFileName, string SourceFolder)
{
string path = SourceFolder;
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + ".xls");
Response.ContentType = "application/ms-excel";
FileStream fs = null;
fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, (int)fs.Length);
fs.Close();
Response.BinaryWrite(data);
Response.End();
}
}
This is my cs file to export datagrid to Excel.
But this code is exporting total records
in to excel. I want to insert only 10 records.
Paging is there in the DataGrid,at a time i am
displaying 10 records.When i am giving Export
it must insert only 10 records.What should i
change in this code.Thanks in advance
|
|
|
|
|
Surely its obvious?
foreach (DataRow drow in datatable.Rows)
{.......
is going to read all the records. You need to control the loop a different way, either using a counter or
for (int ctr =0 ;ctr<10; ctr++)
{
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Hi,
This is what i had in mind.
Solution1
-Project1
-Default.aspx
-Project2
-UserControl\Usercontrol1.ascx
-Default.aspx
Now, what I need is to use Usercontrol1.ascx to Default.aspx in Project1.
Usercontrol1.ascx is used in local Default.aspx in Project2.
Also Project1 & Project2 are in the same solution under Solution1.
So anyone knows how to do this?
Thanks.
|
|
|
|
|
i think u need to add this usercontrol to both project
|
|
|
|
|
|
So I spent a few days developing a personal website in Visual Studio 2005 (I do have access to 2008 if need be) and created a "portfolio" folder containing samples of my previous work. I wanted this folder protected, so I made a login.aspx page and dropped in a login box from the toolbar. I also went to web site administration and required authentication for the folder. Everything worked fine in testing using my computer as the local server. I purchased a website, bought hosting from Omnis and have my site stored on a Windows server.
My problem: SQL Server 2005 is not supported, so my login page and SQL Express DB aren't working.
What are my options as far as fixing/reconfiguring go? My web host supports Access and MySql.
Any help would be greatly appreciated. I'm a bit novicial and need to find out the best practice in a situation like this.
|
|
|
|
|
U check any other sql 2005 supporting server. U host ur database that server.
and u give u r connection string using http path
|
|
|
|
|
i have three pages and i want to make one of them to load as the index page , how can i set a page as the main .
|
|
|
|
|
prasadbuddhika wrote: i have three pages and i want to make one of them to load as the index page , how can i set a page as the main .
In solution Explorer Right Click on the page that you want to load first. Click "Set As Start Page "
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
Hello everyone ,
I've got a gridview and it's sqldatasource . I;ve done some changes to the grid view(added some columns) and now i want to modify a query from the datasource ( corresponding to changing only one column with another one in the grid view ) . But when i try to recreate the query for the sqldatasource , the gridview loses all the new columns i had added manually ( bound fields , image fields etc ) . How can i keep them and just modify one column ?
Thank you !
|
|
|
|
|
In an ASP.Net Visual Studio 2005, How can you edit the string value for a Gridview SqlDataSource SelectCommand?
For example, I need to replace SelectCommand="Select * from [Table1]" with SelectCommand="Select * from [Table2]"
Code snippet Example:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
&nbsp;<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="Office Number" SortExpression="O Number">
.... etc..
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status">
<HeaderStyle BackColor="#EBFFEB" />
</asp:BoundField>
.... etc..
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=(serverName);Initial Catalog=(databaseName);Integrated Security=True" SelectCommand="Select * from [Table1]"></asp:SqlDataSource>
|
|
|
|
|
To Clarify: I need to conditionally, programmatically change the string value from 'Select * from [Table1]' to 'Select * from [Table2]'
I have tried various ASP <%#variable%> techniques without success.
I have also tried the following (In the Page_Load and a Button1_Click sub) :
Dim SqlDatasource1 As New SqlDataSource
Dim GridView1 As New GridView
Dim sSQLDataSource As String
sSQLDataSource = "Select * from [Table2]"
Dim SqlConnectionString As String
SqlConnectionString = "Data Source=(serverName);Initial Catalog=(databaseName);Integrated Security=True"
SqlDatasource1.ConnectionString = SqlConnectionString
SqlDatasource1.SelectCommandType = SqlDataSourceCommandType.Text
SqlDatasource1.SelectCommand = sSQLDataSource
SqlDatasource1.DataBind()
GridView1.DataSource = SqlDatasource1
GridView1.DataBind()
....
Any enlightenment with what I'm missing with the Bound GridView would be greatly appreciated.
|
|
|
|
|
Just in case this can help anybody else, the only solution I was able to find around the Bound GridView SelectCommand was to use a store procedure and pass parameter options via Session variables to return dynamic record sets.
|
|
|
|
|
Hi,
I'm an A level student in the UK studying computing. For my project, I have to create a website for a real company. I'm using Visual Web Developer 2008 Express Edition along with MS Access for a database.
I've come across a slight problem which I don't yet have the knowledge for and was wondering if somebody could enlighten me. You see, I have a news page, which uses a datalist which is bound to an MS Access database. This datalist uses a query to display:
- ID (Hidden)
- Heading
- Date published
The database itself also holds the article as a memo in a field. I want to implement a button, which will redirect the user to a page containing the article. My idea was to send the ID of the record from the datalist to another page, and use this information as an integer on the next page for a query, which will select the matching article (matching the article ID to the integer), and present it on the page. Here are the code snippets to help understand better:
News.aspx
<asp:datalist id="DataList1" runat="server" datakeyfield="ID" xmlns:asp="#unknown">
DataSourceID="NewsDataSource">
<itemtemplate>
ID:
<asp:label id="IDLabel" runat="server" text="<%# Eval("ID") %>" />
<br />
Heading:
<asp:label id="HeadingLabel" runat="server" text="<%# Eval("Heading") %>" />
<br />
Published on:
<asp:label id="Published_onLabel" runat="server">
Text='<%# Eval("[Published on]") %>' />
<br />
<br />
<asp:button id="GoToArticle" runat="server" onclick="Go_To_Article" text="Read More" commandargument="<%# Bind("ID") %>" />
</asp:label></itemtemplate>
</asp:datalist>
The Code-behind for News.aspx
'Event to transfer page control to NewsArticle.aspx
Protected Sub Go_To_Article(ByVal sender As Object, ByVal e As EventArgs)
Dim IDLabel_Value As Integer
IDLabel_Value = 'here is where I don't know how to select the ID field of datalist1
Response.Redirect("~/NewsArticle.aspx?IDLabel_Value = " & CStr(IDLabel_Value))
End Sub
And I don't know how to retrieve the ID value send to NewsArticle.aspx I have looked up on a method which uses get property on the first page and then Dim As Result on the second page. But even then, I don't know how to retrieve the ID field of the record from a datalist. Any help would be greatly appriciated.
Thanks!
|
|
|
|