|
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!
|
|
|
|
|
If you select a record on page 1 and then need to use it in page 2, there's two common ways to do this:
1 - make page 1 and page 2 controls on the one page and let viewstate store it
2 - write a generic page to show a record based on id, and pass the id in on the URL. This second way has the advantage that people can bookmark the same page with different ids on the URL and go back to them.
You can also use cross page postback in later versions of .NET but that is really hacky.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
you can pass the id in query string[^].
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
LOL - thanks, I didn't think of that.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks christian and yusuf for the help. I've never tried to post using a query; I gave it a shot but now I get the following error when clicking on the button:
System.NullReferenceException: Object reference not set to an instance of an object.
for line
Response.Redirect("~/NewsArticle.aspx?ID=" + this.IDLabel.Text);
I'm not sure, but I think it may have something to do with the fact that i've used
<asp:label id="IDLabel" runat="server" text="<%# Eval("ID") %>" xmlns:asp="#unknown" />
here (if xmlns:asp="#unknown" shows up that's really not there...it just shows up in the preview :P). So here is the overall code behind:
public partial class News : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label IDLabel;
protected System.Web.UI.WebControls.Button GoToArticle;
protected void Page_Load(object sender, EventArgs e)
{
}
public void Go_To_Article(object sender, System.EventArgs e)
{
Response.Redirect("~/NewsArticle.aspx?ID=" + this.IDLabel.Text);
}
}
I had followed the tutorial yusuf kindly linked me (and thank you for it ^_^), but i noticed in the source code, the author is using <form method="post"></form> , whereas I can't put a form in my news.aspx page because I've already implemented one in the master page. This has proven to be one hell of a coursework!
Thanks.
|
|
|
|
|
The problem is probably that IDLabel is inside a template, there's not ONE IDLabel to refer to, they are buried in the gridview. What you do is use that <%# Eval syntax to render a button or link for each row, I'd use a linkbutton if you need a button on the form. Then you build your URL with the query parameter inside the list, so the id is rendered correctly for each row.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Arroci wrote: This has proven to be one hell of a coursework!
As long as you are willing to learn, we are here to help. don't give up.
Before implementing something, I would spend sometime understanding the basics. using query string is not that difficult at all. Try debugging your code and see what is the value of
this.IDLabel.Text
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
ah! I think you and christian have found the source of the problem. Christian was right in saying the IDLabel does not have one thing to refer to. Your suggestion on debugging
this.IDLabel.Text seemed to have proved it because it's saying NullReferenceException was unhandled, which probably could be concluded that it's just not getting the ID value off the datalist.
Hehe I figured, the only way to really challenge myself is to just stretch my resources as much as possible to get information I need . But this has proven quiet trivial and my books don't cover this. Google works to some extend but it's a bit tricky to learn independant methods and then try to fuse them and translate to one language. Nethertheless I do enjoy it ^_^.
So I guess the next step really is how to render a link button in the <%# Eval("ID") tag? Any links to tutorials and suggestions are welcome ^_^.
Big thank you to christian and yusuf for helping me out. You guys rock!
|
|
|
|
|
I'm glad to see you doing all the hard work. Many people here will be willing to support you as long as you keep the good work. What people hate here is, if you simply ask for the source code.
Don't feel bad, we're all like you at some point of time. Keep reading and learning. Don't be afraid to ask any question. As long as you are willing to learn, we will entertain all of your questions.
Arroci wrote: So I guess the next step really is how to render a link button
what do you mean? I did not get it?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
something like this seems to be working now BUT it doesn't seem to pick up the Eval. I think Christian meant something like this:
<asp:linkbutton id="GoToArticle" onclick="Go_To_Article" runat="server" xmlns:asp="#unknown"><![CDATA[<%# Eval("ID") %>]]></asp:linkbutton>
Note: [xmlns:asp="#unknown">] is supposed to be [><%# Eval("ID") %>]. Don't know why it comes out messed up but there you go
Now this button works because it goes to the next page but it doesn't submit the query string however I know why and that's because I don't know how to extract the Eval("ID") from the button hehe. So the part i'm stuck on is this:
Response.Redirect("~/NewsArticle.aspx?ID=" + this.GoToArticle)
I know (well, I get the feeling) that the this.GoToArticle is supposed to be expanded more but the intellisense is confusing me haha. I have placed the Eval in between the opening tag of the link button and the closing tag of the link button. If I could extract this value (maybe as a string?) it might fix it. I have a hunch I should be able to, because you can extract values from text boxes as strings. ]]>
|
|
|
|