|
I'm having issues sorting a GridView whose datasource is dynammically determined by which report is selected from a drop down. I know sorting is an easy thing if I used a SQLDataSource or an ObjectDataSource and maybe created a table adapter for each report I'm pulling but the idea was to only have to make changes in sql server when new reports are added rather than having to modify any code. Any ideas on how I can sort this dynamically filled GridView? I'm running into an StackOverflowException was unhandled error probably becuase GridView1 doesn't have bound columns or something like that I imagine. When stepping through the code I see e.SortExpression does have the column name in there but it's not working. The RunRptButton_Click event is what the user clicks after selecting the report from a drop down and filling out two text fields for start date and end date (used free daintydate datepicker). And please, if there is a better approach, any help would be great. Here's my code...
<asp:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle" AutoGenerateColumns="True" AllowSorting="true" OnSorting="Sort_GridView">
</asp:GridView>
protected void RunRptButton_Click(object sender, EventArgs e)
{
try
{
DateTime StartDate = System.Convert.ToDateTime(DaintyDate1.Text);
DateTime EndDate = System.Convert.ToDateTime(DaintyDate2.Text);
SqlCommand cmd = new SqlCommand(RptsDropDownList.SelectedItem.Value, new SqlConnection(
WebConfigurationManager.ConnectionStrings["SID_RequestConnectionString"].ConnectionString));
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("StartDate", StartDate);
cmd.Parameters.AddWithValue("EndDate", EndDate);
//cmd.Parameters.AddWithValue("StartDate", "2006/01/01");
//cmd.Parameters.AddWithValue("EndDate", "2007/01/01");
cmd.Connection.Open();
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
cmd.Connection.Close();
cmd.Connection.Dispose();
}
catch (Exception ex)
{
lblErr.Text = "Error: " + ex.Message;
}
}
protected void Sort_GridView(object sender, GridViewSortEventArgs e)
{
try
{
GridView1.Sort(e.SortExpression, SortDirection.Ascending);
}
catch (Exception ex)
{
lblErr.Text = "Error Sorting: " + ex.Message;
}
}
Darren
-- modified at 12:58 Wednesday 28th February, 2007
|
|
|
|
|
I figured out a way to do this with minimal changes by adding a table adapter for each report but if anyone knows a way for me to avoid this, please let me know. No code was necessary for sorting. For those who may want to see this...
I added a table adapter for each report (about 10). In the code below, I have SelectMethod and TypeName hardcoded but that will actually be populated from a table in sql server based on the report they choose from a drop down.
create an ObjectDataSource with just the bare bones
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}">
</asp:ObjectDataSource>
GridView with also minimal config
<asp:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle" AutoGenerateColumns="True" AllowSorting="true">
<HeaderStyle CssClass="HeaderStyle" />
<AlternatingRowStyle CssClass="AlternatingRowStyle" />
</asp:GridView>
button to run report
<asp:Button ID="RunRptButton" runat="server" Text="View Report" OnClick="RunRptButton_Click" />
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
else
{
// must have this for sorting!
ObjectDataSource1.SelectMethod = "GetRptSIDRevisionCount";
ObjectDataSource1.TypeName = "ReportsBLL";
}
}
protected void RunRptButton_Click(object sender, EventArgs e)
{
try
{
DateTime StartDate = System.Convert.ToDateTime(DaintyDate1.Text);
DateTime EndDate = System.Convert.ToDateTime(DaintyDate2.Text);
ObjectDataSource1.SelectMethod = "GetRptSIDRevisionCount";
ObjectDataSource1.TypeName = "ReportsBLL";
ObjectDataSource1.SelectParameters.Add("StartDate",Convert.ToString(StartDate));
ObjectDataSource1.SelectParameters.Add("EndDate", Convert.ToString(EndDate));
GridView1.DataSourceID = ObjectDataSource1.ID;
GridView1.DataBind();
}
catch (Exception ex)
{
lblErr.Text = "Error: " + ex.Message;
}
}
Now when I add a new report I'll have to add the report info to the table in sql server and unfortunately still have to go in and create a table adapter for the new report. I'd love to not have to do this if anyone knows a better way. Thanks!
|
|
|
|
|
Anyone every hear of any software that tracks users click and records them to a DB or something. We have a decent error trapping process in place but it very hard to try to recreate the error that the user caused. Any thoughts?
|
|
|
|
|
Why cant you trace the information from exceptions with the user clicks...When an error generates it need to log the message exception also to your DB...
Thanx,
RPM.
Why humans having 99.9% of unused brain!!!
|
|
|
|
|
Hi all,
I have a web page that contains a link that is connected to an attachement.Clicking on that link brings up a small window that allows me to save/open the attachment.It works fine without SSL. but once I use https:// and click on the same link I get the following error:
Internet explorer cannot download file from server.
IE was not able to open the site.The requested site is either unavailable or cannot be found.
Any ideas why this is happening?
Any help would be appreciated.It is on the .NET 2.0 framework.
Thanks.
CafeDreamz.
|
|
|
|
|
hi all,
I am trying to access a web application built on the .NET 2.0 framework and I keep getting this error pop-up which asks me to select a debugger....
The error is:
system.security.cryptography.cryptographicexception caused by w3wp.exe(which is the w2k3 worker process).
any ideas why this is happening?
any help would be appreciated.
Thanks.
Cafedreamz.
|
|
|
|
|
assalam-o-alaikum!
dears i want to provide the download option at my site please tell about the code....have you any idea about download...?
Feroze
|
|
|
|
|
Just make files a link.
it will does automatically.
Naveed Kamboh
|
|
|
|
|
Assalam-o-Alaikum dear Naveed thanks for reply me yaar. please give me some idea about link or some code to do this....thanxxxxx....
Feroze
|
|
|
|
|
Feroze its v.easy and simple
for example "Download my CV"
Naveed Kamboh
|
|
|
|
|
You can stream the file right?
|
|
|
|
|
Hi,
I want to share this problem. I have a datagrid that will help me Insert data into sql database. So I made a button On my form so that when I press the button a new row on datagrid should be created and I could be able to insert data. But with this code below I've failed could someone help me and tell me where I'm going wrong:
private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
Fill();
Bind();
}
}
DataTable table = new DataTable();
private void Fill()
{
SqlDataAdapter adapter = new SqlDataAdapter("select * from dbo.DashBoard", con);
adapter.Fill(table);
}
private void Bind()
{
dgis.DataSource = table;
dgis.DataBind();
}
private void InsertEmpty()
{
table.Rows.InsertAt(table.NewRow(), 0);
}
private void bttnew_Click(object sender, System.EventArgs e)
{
// inserting
dgis.EditItemIndex = 0;
// modify text
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Update";
// fill table, insert empty row, bind to datagrid
Fill();
InsertEmpty();
Bind();
}
private void dgis_ItemCommand(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// stop editing
dgis.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
break;
case "Update":
break;
case "Cancel":
break;
case "Edit":
// begin editing
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
dgis.EditItemIndex = e.Item.ItemIndex;
break;
}
// fill and bind
Fill();
//InsertEmpty();
Bind();
}
Thanks.
|
|
|
|
|
A popup window on a form does not move when I scroll up or down the web page. How can I correct this so that the popup window moves with the rest of the form when scrolling.
|
|
|
|
|
|
after i made my website and aspx pages
and i upload the website
i recive this error
Server Error in '/' Application.
-----------------------------------------------------------------------------
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
<configuration>
<system.web>
<customerrors mode="Off">
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.
configuration>
<system.web>
<customerrors mode="RemoteOnly" defaultredirect="mycustompage.htm">
----------------------------------------------------------------------------
so can any one solve this problem
or tell me what shall i do ?
thanks all
bye
Ahmed EL Gendy
|
|
|
|
|
It seems that there is an error in your code. To view this error from the server, make sure the custom error attribute is set to Off in your web.config file like,
<customErrors mode="Off"/>
thanks,
Mubashir
Every job is a self portrait of the person who did it.
|
|
|
|
|
Hi, I've recently discovered the beauty of serialization and my problem is that I want to access the parent member set by the serialization and get the value, this upon creation of course. I'm using three classes, the Parent-class, the Children-class and the ChildCollection-class. Now, I want the childrens created to have the same last name as the parent. When I try to use base.value it's null/empty. Anyone have any suggestions on how to solve this?
Parent class
<br />
[Serializable()]<br />
public class Parent<br />
{<br />
private string _strName;<br />
private string _strLastName;<br />
private ChildCollection m_Children;<br />
<br />
[XmlAttribute("name")]<br />
public string Name<br />
{<br />
get { return _strName; }<br />
set { _strName = value; }<br />
}<br />
<br />
[XmlAttribute("lastName")]<br />
public string LastName<br />
{<br />
get { return _strLastName; }<br />
set { _strLastName= value; }<br />
}<br />
<br />
public Parent()<br />
{<br />
m_Children = new ChildCollection();<br />
}<br />
}
The ChildCollection class
<br />
public class ChildCollection : CollectionBase<br />
{<br />
public Child this[int index]<br />
{<br />
get { return (Child)this.List[index]; }<br />
set { this.List[index] = value; }<br />
}<br />
<br />
public void Add(Child child)<br />
{<br />
this.List.Add(child);<br />
}<br />
<br />
public void Add(string name, string lastName)<br />
{<br />
this.Add(new Child(name, lastname));<br />
}<br />
The Child class
<br />
[Serializable()]<br />
public class Child : Parent<br />
{<br />
private string _strLastName;<br />
<br />
[XmlAttribute("name")]<br />
public new string Name<br />
{<br />
get { return _strName; }<br />
set { _strName = value; }<br />
}<br />
<br />
[XmlAttribute("lastName")]<br />
public new string LastName<br />
{<br />
get { return _strLastName; }<br />
set { _strLastName = base.value; }<br />
}<br />
<br />
public Child() {}<br />
}<br />
|
|
|
|
|
What you are doing doesn't really make sense. You don't have a public property for your Childred collection on your Parent class. You are defining Name and Lastname again on your child class when they are already defined in your Parent class that you are inherting from. If you are trying to serialize your parent class the child collection would be null since there is no public property.
I guess I would take a step back and think through what you are trying to accomplish with this design. Normally your base class would have public properties that would be shared with all children. Then the children would introduce new properties.
Now if your Parent class was in interface instead, then you would have to implement all of the public properties.
Anyway, I am not sure if any of that is helpful.
Ben
|
|
|
|
|
It was just to be clear with things, I do know I do not have to declare the same properties again, and the private variables should be protected. But you do understand the concept? Or else, don't bother answer. Well the real class have other properties, this is just and examble!
|
|
|
|
|
hi friends
Now i am developing one site.i need to set alert frequency,it use to send the
message through mail(here option is daily,weekly,monthly) to client..
if u have any doubt plz refer this link:
http://www.99acres.com[^]
how can i achieve this.plz send me code and related links;
regards
saravanan
|
|
|
|
|
You may need a Windows service to poll and send an email.
|
|
|
|
|
Hello
After log in to the application the textbox to disply the name of the person log in the application(automatically).And after selecting the date from the calender the label to display trhe week number(automatically).on the next web page
BoipeloMothusi
|
|
|
|
|
Was there a question in there or is it just me?
|
|
|
|
|
Yes, but you have to use your decoder ring from Ovaltine.
|
|
|
|
|
After log in to the system the textbox on the next webpage to display the name of the person log on to the system
OlgaM
|
|
|
|