|
hi,
Here i add a sample code for sorting
1) In Gridview Properties add this
AllowSorting="true" OnSorting="gridView1_OnSorting"
2) In gridView use TemplateField Column
<asp:TemplateField HeaderText="joiningdate" HeaderStyle-HorizontalAlign="Left" SortExpression="joiningdate" ItemStyle-Width="30%">
<ItemTemplate >
<span id="joiningdate" runat="server" style="color:Black;" ><%#Eval("joiningdate") %></span>
</ItemTemplate>
</asp:TemplateField>
3) create a Event gridView1_Onsorting
protected void gridView1_OnSorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression;
ViewState["sortExpression"] = e.SortExpression;
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression, "DESC");
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression, "ASC");
}
}
4) Create a SortGridView() Method
private void SortGridView(string sortExpression, string direction)
{
DataTable dt = null;
dt = "test" // fill the Datatable rows using sqlcommand or Dataset
DataView dv = new DataView(dt);
dv.Sort = sortExpression + " " + direction;
gridView1.DataSource = dv;
gridView1.DataBind();
}
5) Create a enum SortDirection
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
}
|
|
|
|
|
Hi,
How to save data from a html table to database.
eg: my html table, it is dynamically generated using string concadination
name age address city
N1 10 xyz abc
N2 20 abc xyz
I need to read this html table and save it to database
How to do this?
Thankyou
YPKI
|
|
|
|
|
Say you paste the html into a container div. Now you can get the inner HTML in the server side of the div. Now parse the table from it.
Otherwise if you like to create the entire htmlTable with view state and all, you need to create the object during pre_Init.
|
|
|
|
|
This is the chat box where every second gets refresh with AJAX. But,here the dataset (ds) is filled by other order detail, lead to get wrong messages in the chat box.
How to fill ds for every second from SQL database without conflict?
VB Code
lsSQL = "select MSG_Message from tbl_message where MSG_Orderno='" & orderno & "' order by MSG_ID"
Dim DtSqlAdp6 As New SqlClient.SqlDataAdapter(lsSQL, DbCon)
DtSqlAdp6.Fill(ds)
|
|
|
|
|
Good Day j_u_sankar
There is Probably a better way of doing this, but anyway. To Clear the dataset you must Add the Following code
DtSqlAdp6.Clear()
before you fill the dataset.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Dear Experts,
i've designed a crystal report and embedded a sub report in it, the sub report needs to display some 7 records (i.e 7 lines), the design goes this way
i've few detail sections then the sub report is inserted in a detail section followed by few detail sections, the issue here is when i check preview the report detail sections are displayed perfectly when comes to question of sub report its display 2 records repeatedly for pages together(approx 5 pages) and at the 5th page its dispalying all the records perfectly, later the same pages are repeated again.
i'm using the same stored procedure in both the main and sub report.
if some one has come across this sort of issue plz let me know how to overcome, i will be happy to explain you the problem in detail if some one is interested.
Thanks in advance
Murali..
|
|
|
|
|
hii...
all.I m using asp.net 3.5.I have a feedback form.On the click of button i want to send mail.how can i do this.
can anybody send me a gud link which is self explanatory.
thanks....
|
|
|
|
|
|
|
i have just did a copy and Paste from my old Function that does that when ever there is an Erro on my applicatin
private void Send_log()
{
String Client_Domain = System.Environment.MachineName.ToString();
Exception objErr = Server.GetLastError();
String FromE = ConfigurationManager.AppSettings.Get("FromE");
String To_1 = ConfigurationManager.AppSettings.Get("EmailTO1");
String To_2 = ConfigurationManager.AppSettings.Get("EmailTO2");
String Gmail_Password = ConfigurationManager.AppSettings.Get("Gmail_Password");
String Networked_Username = ConfigurationManager.AppSettings.Get("Networked_Username");
int Gmailport = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Gmailport"));
String Server_Host = Convert.ToString(ConfigurationManager.AppSettings.Get("GmailHost"));
String Body = Convert.ToString(Application["testError"]);
System.Environment.UserDomainName.ToString();
try
{
if (Body != "")
{
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress(FromE);
mm.To.Add(new MailAddress(To_1));
mm.To.Add(new MailAddress(To_2));
mm.Subject = "Exception Report from " + Client_Domain + "In EXAM/CLASS";
mm.Body = Body;
mm.IsBodyHtml = true;
smtp.Host = Server_Host;
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = Networked_Username;
NetworkCred.Password = Gmail_Password;
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = Gmailport;
smtp.Send(mm);
}
else
{
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress(FromE);
mm.To.Add(new MailAddress(To_1));
mm.To.Add(new MailAddress(To_2));
mm.Subject = "Exception Report from " + Client_Domain + "In EXAM/CLASS";
mm.Body = "An Exception Occured, but it has not Been Realised.You can Wait for the Client to log a Fault";
mm.IsBodyHtml = true;
smtp.Host = Server_Host;
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = Networked_Username;
NetworkCred.Password = Gmail_Password;
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = Gmailport;
smtp.Send(mm);
}
}
catch (ApplicationException ex)
{
Response.Write(ex.Message);
}
}
as you can see the code, the values are comming from a webConfig, you can change them so that they come from your ASP.NET page.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi!
Can someone please tell me how I can retrieve the UserId from the aspnet_users table when I use the login tools in ASP.NET?
I am logging in as registered user and then when I click on edit profile I need the edit profile page to load with the UserId because I have made a one-to-one relationship between aspnet_users and Person table.
I am using a DataSet in a Seperate DAL. Basically I have configured the query to select record by UserId but I cannot get the correct GUID value from the aspnet_users table when going to editprofile page.
Thank you!!
Illegal Operation
|
|
|
|
|
u can get the UserId of any user via it's UserName. Firstly u can get the instance of MembershipUser then from this instance u will be able to get the Guid or UserId of that user. This same value is going to store in the aspnet_users table.
MembershipUser user = Membership.GetUser("UserName");
Guid userId = (Guid)user.ProviderUserKey;
You can get the UserName of the currently loggedin user via Context.User.Identity also.
|
|
|
|
|
Hi, everyone. The situation is, I am converting a tiff image file into byte[], then to stream then saving it as jpeg image format, then display it on browser, so that the jpeg opens in a picture viewer instead of webpage. The code works in IE 6 and firefox, but does not work in IE 7. In IE 7, the blank page appears and automatically closes. The code is as follows:-
System.IO.Stream _stream = new MemoryStream(byteArray);
Bitmap _bmp = new Bitmap(_stream);
Response.Clear();
Response.AddHeader("Content-Disposition","attachment;filename=adc.gif");
Response.ContentType = "image/gif";
_bmp.Save(Response.OutputStream, ImageFormat.Gif);
Response.End();
_bmp.Dispose();
_stream.Close();
This code is called in the page_load of a page in server a. Since the tiff image is located on a different server(server b) other than the web server, the image path is passed to web service located at server b, image is read and converted to byteArray and returned to server a. I guess the problem is with Content-Disposition.
Any help is appreciated.
|
|
|
|
|
Try this
============
byte[] message; // converting a tiff image file into byte[]
bool ret = false;
string filepath = "C:\";
if (Contentdisposition != null)
{
ret = Contentdisposition.StartsWith(" attachment;");
//code to decode the data
if (ret && (contentTransferEncoding.ToUpper().Equals("BASE64")))
{
//create the file and store the binart data
//store to test create the file with attachment name later
string[] filename = Contentdisposition.Split(';');
attachfile = filename[1];
attachfile = Regex.Replace(attachfile, "^[ | ]+filename=[\"]*([^\"]*).*$", "$1");
filepath+=attachfile;
m_binaryData = Convert.FromBase64String(message.Replace("\n", ""));
System.IO.BinaryWriter bw = new BinaryWriter(new FileStream(filepath, System.IO.FileMode.Create));
bw.Write(m_binaryData);
bw.Flush();
bw.Close();
}
}
|
|
|
|
|
I will begin by stating that I am NOT an ASP.NET developer. My new job now pushes me into it.
So with that said I'm trying to do the following:
This asp app is a single screen with the top 2/3 a bunch of dropdowns that the user selects to isolate a specific location.
Once that location is set, I need to dynamically add 4 - 6 legs which the user will provide the name for each leg.
I want to do this one leg at a time so I have a place holder named insertHere and a usercontrol with a lable, textbox, and button which says "Next Leg".
When I click the button Create Legs....my first leg control shows just fine. I enter a leg ID and click the Next Leg button (part of the control). My Next Leg process is this:
protected void NextEventHandler(object sender, EventArgs e)
{
if (NextEvent != null)
{
this.next.Visible = false;
NextEvent(sender, e);
}
}
The idea is to make the button invisible then fire the NextEvent up to the parent container. My NextEvent code is simple right now:
protected void HandleNextEvent(object sender, EventArgs e)
{
CreateLegsRequestHandler(sender, e);
}
What happens is this: when I click the button Next Leg, my entire control goes invisible and I do not see either the Leg One control or the Leg Two control being displayed. I'm puzzled and confused. Can the ASP.NET gods please help me with why it isn't working?
My desired result:
xxxxx dropdown
xxxxx dropdown
xxxxx dropdown
xxxxx dropdown [Create Legs]
(within PlaceHolder(insertHere).Controls)
Leg 1 textboxValue1 -invisible buttons-
Leg 2 textboxValue2 -invisible buttons-
Leg 3 textboxValue3 -invisible buttons-
Leg 4 _____________ [Next Leg] [Done]
|
|
|
|
|
Dynamic controls created like this will not have viewstate persisted. When you use dynamic controls, you need to recreate it on every postback.
Michael Eber wrote:
(within PlaceHolder(insertHere).Controls)
Leg 1 textboxValue1 -invisible buttons-
Leg 2 textboxValue2 -invisible buttons-
Leg 3 textboxValue3 -invisible buttons-
Leg 4 _____________ [Next Leg] [Done]
What you need here is to display tabular data. GridView will be the best control and it handles viewstate very well. To get your desired result, use a GridView with necessary columns. Use TemplateColumn to display text box and button. When Create Leg is clicked, add a new row to the GridView 's data source and rebind the gridview.
|
|
|
|
|
Okay...I've been tinkering with this so far and have a few questions....
First: I have a dropdown box and I defined an OnSelectedIndexChange event. When I run the application and I select an item in the dropdown box, my next dropdown box is not populated!
UIPDATE: I believe I got this fixed. Set the dropdowns to AutoPageBack (or something like that).
Second: When I add dropdown lists to the GridView do I also use a TemplateColumn?
Finally: I must be using the TemplateColumn incorrectly. If it is in the Gridview it complains no such type exists.
If I add a <Column> header then add the TemplateColumn I get a different error. Where to I add the TemplateColumn?
Do I use a <Field> header instead?
modified on Monday, September 28, 2009 12:57 PM
|
|
|
|
|
On my page I have a plain Gridview Control.
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
In the code behind, I populate a dataview and bind it to the Gridview.
Me.GridView1.DataSource = objSF.DV
Me.GridView1.DataBind()
This works fine.
Now I want to change the formatting of column(4) to be formatted as currency.
I've tried, CType(Me.GridView1.Columns(4), BoundField).DataFormatString = "{0:c" , in various Gridview events with no success;
in fact, it appears that everywhere I try the above code, the Grid reports that there are no columns at all !
I've used, System.Diagnostics.Debug.WriteLine(Me.GridView1.Columns.Count.ToString) in the following events and gotten zero as a result.
GridView1_RowCreated
GridView1_DataBound
GridView1_PreRender
GridView1_RowDataBound
What am I doing wrong ?
How can I format a column to display the data as currency ?
Regards,
David
|
|
|
|
|
From ASP.NET 2.0 everything is encoded using HTMLEncode which prevents any modification being done to the bound controls. Just use like this :
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="CurrencyField" HeaderText="Amount" DataFormatString="{0:c}" HtmlEncode="false" />
</Columns>
</asp:GridView>
You can see I placed HtmlEncode=false .. This is required for every BoundField in Gridview to reformat the data.
I am hoping this would work...
|
|
|
|
|
You can also covert it in Template Field then format the value as you want and bind to the control in RowDataBound Event.
|
|
|
|
|
Thank you for your input. For now, I have traced back where the dataset is populated and used the following to format the data.
SQLcmd.Parameters("@ORDERVALUE").Value = String.Format("{0,15:c}", dAmt)
This is OK for now.
|
|
|
|
|
Hey David
You have solved your problem this way but it's not the efficient way to work if u r working on project following n tier architecture and MVC design pattern. In that case the data service should return the data in most common/raw format and then presentation layers should convert them as per the requirement. So if have multiple views using the same data service can display the data as per their requirements. They are not bound to display the original one.
|
|
|
|
|
Very true about returning data in a common format and have the presentation layer handle the formatting. I'll remember that in future designs.
Btw: This report is not finished, so it may get scrapped completely. A meeting with management is scheduled for this morning.
|
|
|
|
|
Hi..
How can I change the alert messages title..
thanks
By:
Hemant Thaker
|
|
|
|
|
Hemant Thaker wrote: How can I change the alert messages title..
You Can't !
The only thing you can do, create your alert using DIV. Make it Float. Use Custom Header Title and Button
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|