Wednesday, March 28, 2012
trouble binding a datagrid to a custom collection
success.
I'm getting this error:
DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks
.
Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form>
//----
Code behind:(NewsContent.aspx.cs).
public class NewsContent{
private void Page_Load(object sender, System.EventArgs e)
{
ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}
private ListItemCollection AddToCustomCollection()
{
ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);
return myListCollection;
}
//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}
//----
--
I'm using a collection class: (ListItemCollection.cs):
public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}
public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}
public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}
}Try setting the autogeneratecolumn property for this datagrid to True.
"viktor9990" wrote:
> I'm trying to bind a custom collection to an autogenerated datagrid withou
t
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Than
ks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //----
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2"
,
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //---
--
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }
trouble binding a datagrid to a custom collection
success.
I'm getting this error:
DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks.
Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form
//---------------------
Code behind:(NewsContent.aspx.cs).
public class NewsContent{
private void Page_Load(object sender, System.EventArgs e)
{
ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}
private ListItemCollection AddToCustomCollection()
{
ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);
return myListCollection;
}
//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}
//------------------------
I'm using a collection class: (ListItemCollection.cs):
public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}
public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}
public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}
}Try setting the autogeneratecolumn property for this datagrid to True.
"viktor9990" wrote:
> I'm trying to bind a custom collection to an autogenerated datagrid without
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Thanks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //---------------------
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //------------------------
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }
Saturday, March 24, 2012
trouble setting text values in custom controls
i have created a simple custom control with a simple text label on it. This is the ascx code for my control.
I have removed the compiler generated stuff to save space.
It has a simple text label on it - called lbBanner
PublicClass BannerAndGrid 'this is my custom control class
Inherits System.Web.UI.UserControl
ProtectedWithEvents lbBannerAs System.Web.UI.WebControls.Label 'this is my text label on my custom control
PrivateSub Page_Init(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.InitInitializeComponent()
EndSub
PublicProperty Banner() ' this property should get/set the text field on the text labale on my custom control
Get
Return lbBanner.Text
EndGet
Set(ByVal Value)
lbBanner.Text = Value'WHEN I DO THIS I GET AN ERROR SAYING THAT THE OBJECT IS NOT SET TO AN INSTANCE OF THE OBJECT
EndSet
EndProperty
EndClass
I instantiate my control thus:
dim aControl as BannerAndGrid
aControl = new BannerAndGrid
aControl.Banner = "abc" ---see above property Banner--when I do this I get a reference error - WHY ?
I cannot see why I cannot set values within my control by using properties to set/get values.
Am I doing something wrong or is there a better way?
All help greatly appreciated.
Cheers.
When you are dynamically creating UserControls you should use LoadControl, rather than instantiating it in the way you are doing. For example:
dim aControl as BannerAndGrid
aControl = CType(LoadControl("/location/of/BannerAndGrid.ascx"), BannerAndGrid)
aControl.Banner = "abc" 'This will work.
Thanks Steven - the above solution worked perfectly.
Cheers
Chas (Canterbury,UK)
Trouble Using Custom Controls
------------------------
I've read a few articles and have put together a custom control. At the moment it simply outputs today's date for testing purposes. My asp page has two key lines.
Code:
<%@dotnet.itags.org. Register TagPrefix="CustomASP" Namespace="DBControls" Assembly="DBCalendar" %>
...
<CustomASP:DBCalendar Runat="Server" /
When I surf to the page I get:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type DBControls.DBCalendar from assembly DBCalendar, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
Line 26: <CustomASPB:DCalendar Runat="Server" />
Is there some variable I have to toggle in order to start using my own controls? I have it compiled and in the /bin subdirectory.Have you included the DLL for the custom control in your project?
If it makes any difference, I'm using Web Matrix, which may explain why I'm clueless what you mean when you ask if I've included that in my project.
In case someone stumbles upon this googling:
I solved my (two problems).
First, my function didn't have an arguementless constructor which apparantly is required.
Second, I used REGASM to register the DLL (Needs to have both the arguementless constructor above and admin rights on the server). Once this was done, the DLL worked properly.
This is only useful when developing with the ASP.NET Web Matrix, it's my understanding that Visual Studio.Net does this all for you.
Thursday, March 22, 2012
trouble with HttpHandler in firefox 2
IIS 6.0 server, .Net 2.0. I have a file download architecture which
redirects
file download requests to a custom server-side HttpHandler. The
handler gets a stream over the file and "returns" the file via
HttpContext.Response.OutputStream.Write.
This works fine in IE, but with Firefox, I get different behavior: I
see no "save as" dialog for the file download ("Always ask me where
to
save files" is enabled), and from the user perspective, it seems as
though nothing happens.
The redirect seems to be successful: I can debug into the handler
just fine. While stepping through the handler, everything appears to
be "working" just fine, but there are a few strange things that
happen:
1) HttpContext.Response.IsClientConnected returns false (with IE
this
returns true).
2) Even though I'm still writing the file stream to
HttpContext.Response.OutputStream.Write, the client (Firefox) doesn't
respond to this.
I've tried using a Content-Dispostion header, with no luck.
Do these symptoms suggest anything to anyone?
Thanks in advance,
Hawkeye Parkerhawkeye parker wrote:
Quote:
Originally Posted by
Hello,
>
IIS 6.0 server, .Net 2.0. I have a file download architecture which
redirects
file download requests to a custom server-side HttpHandler. The
handler gets a stream over the file and "returns" the file via
HttpContext.Response.OutputStream.Write.
>
This works fine in IE, but with Firefox, I get different behavior: I
see no "save as" dialog for the file download ("Always ask me where
to
save files" is enabled), and from the user perspective, it seems as
though nothing happens.
>
The redirect seems to be successful: I can debug into the handler
just fine. While stepping through the handler, everything appears to
be "working" just fine, but there are a few strange things that
happen:
>
1) HttpContext.Response.IsClientConnected returns false (with IE
this
returns true).
2) Even though I'm still writing the file stream to
HttpContext.Response.OutputStream.Write, the client (Firefox) doesn't
respond to this.
>
I've tried using a Content-Dispostion header, with no luck.
>
Do these symptoms suggest anything to anyone?
>
Thanks in advance,
>
Hawkeye Parker
Are you assign Response.ContentType property according to your file?
Are you assign Response.ContentType property according to your file?- Hide quoted text -
Quote:
Originally Posted by
>
Yes. Yere's a sample header:
4 2 HTTP/1.1 200 OK IEXPLORE (2760) 0x12C8
Date: Mon, 09 Jul 2007 21:22:24 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Length: 19968
"Content-Disposition:
attachment;filename=""Small.doc"";"
Cache-Control: private
Content-Type: application/msword
"hawkeye parker" <haughki@.gmail.comwrote in message
news:1184176150.112307.212860@.o11g2000prd.googlegr oups.com...
Quote:
Originally Posted by
Quote:
Originally Posted by
>Are you assign Response.ContentType property according to your file?-
>Hide quoted text -
>>
>
Yes. Yere's a sample header:
>
4 2 HTTP/1.1 200 OK IEXPLORE (2760) 0x12C8
Quote:
Originally Posted by
"Content-Disposition: attachment;filename=""Small.doc"";"
Those quotes don't belong there...
--
John Saunders [MVP]
hawkeye parker wrote:
Quote:
Originally Posted by
Quote:
Originally Posted by
Are you assign Response.ContentType property according to your file?- Hide quoted text -
>
Yes. Yere's a sample header:
>
4 2 HTTP/1.1 200 OK IEXPLORE (2760) 0x12C8
Date: Mon, 09 Jul 2007 21:22:24 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Length: 19968
"Content-Disposition:
attachment;filename=""Small.doc"";"
Cache-Control: private
Content-Type: application/msword
I made some test example.
I added Handler1.ashx in project. Code:
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/msword";
byte[] cont =
System.IO.File.ReadAllBytes(context.Server.MapPath ("~/MSF.doc"));
System.IO.MemoryStream ms = new System.IO.MemoryStream(cont);
ms.WriteTo(context.Response.OutputStream);
}
public bool IsReusable
{
get
{
return false;
}
}
}
In .aspx file:
<a href="http://links.10026.com/?link=Handler1.ashx">MSF.doc</a>
No more actions. Everything works in IE and Firefox.
Regards,
Mykola
http://marss.co.ua
On Jul 12, 12:10 am, marss <marss...@.gmail.comwrote:
Quote:
Originally Posted by
hawkeye parker wrote:
Quote:
Originally Posted by
Quote:
Originally Posted by
Are you assign Response.ContentType property according to your file?- Hide quoted text -
>
Quote:
Originally Posted by
Yes. Yere's a sample header:
>
Quote:
Originally Posted by
4 2 HTTP/1.1 200 OK IEXPLORE (2760) 0x12C8
Date: Mon, 09 Jul 2007 21:22:24 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Length: 19968
"Content-Disposition:
attachment;filename=""Small.doc"";"
Cache-Control: private
Content-Type: application/msword
>
I made some test example.
I added Handler1.ashx in project. Code:
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/msword";
byte[] cont =
System.IO.File.ReadAllBytes(context.Server.MapPath ("~/MSF.doc"));
System.IO.MemoryStream ms = new System.IO.MemoryStream(cont);
ms.WriteTo(context.Response.OutputStream);
}
public bool IsReusable
{
get
{
return false;
}
}
>
}
>
In .aspx file:
<a href="http://links.10026.com/?link=Handler1.ashx">MSF.doc</a>
>
No more actions. Everything works in IE and Firefox.
>
Regards,
Mykolahttp://marss.co.ua- Hide quoted text -
>
- Show quoted text -
Many thanks Mykola. Yeah, that absolutely works. I'm still having a
problem which I'll address in a separate thread.
trouble with HttpHandler in firefox 2
IIS 6.0 server, .Net 2.0. I have a file download architecture which
redirects
file download requests to a custom server-side HttpHandler. The
handler gets a stream over the file and "returns" the file via
HttpContext.Response.OutputStream.Write.
This works fine in IE, but with Firefox, I get different behavior: I
see no "save as" dialog for the file download ("Always ask me where
to
save files" is enabled), and from the user perspective, it seems as
though nothing happens.
The redirect seems to be successful: I can debug into the handler
just fine. While stepping through the handler, everything appears to
be "working" just fine, but there are a few strange things that
happen:
1) HttpContext.Response.IsClientConnected returns false (with IE
this
returns true).
2) Even though I'm still writing the file stream to
HttpContext.Response.OutputStream.Write, the client (Firefox) doesn't
respond to this.
I've tried using a Content-Dispostion header, with no luck.
Do these symptoms suggest anything to anyone?
Thanks in advance,
Hawkeye Parkerhawkeye parker wrote:
> Hello,
> IIS 6.0 server, .Net 2.0. I have a file download architecture which
> redirects
> file download requests to a custom server-side HttpHandler. The
> handler gets a stream over the file and "returns" the file via
> HttpContext.Response.OutputStream.Write.
> This works fine in IE, but with Firefox, I get different behavior: I
> see no "save as" dialog for the file download ("Always ask me where
> to
> save files" is enabled), and from the user perspective, it seems as
> though nothing happens.
> The redirect seems to be successful: I can debug into the handler
> just fine. While stepping through the handler, everything appears to
> be "working" just fine, but there are a few strange things that
> happen:
> 1) HttpContext.Response.IsClientConnected returns false (with IE
> this
> returns true).
> 2) Even though I'm still writing the file stream to
> HttpContext.Response.OutputStream.Write, the client (Firefox) doesn't
> respond to this.
> I've tried using a Content-Dispostion header, with no luck.
> Do these symptoms suggest anything to anyone?
> Thanks in advance,
> Hawkeye Parker
Are you assign Response.ContentType property according to your file?
> Are you assign Response.ContentType property according to your file... Hide quoted text -[
color=darkred]
>[/color]
Yes. Yere's a sample header:
4 2 HTTP/1.1 200 OK IEXPLORE (2760) 0x12C8
Date: Mon, 09 Jul 2007 21:22:24 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Length: 19968
"Content-Disposition:
attachment;filename=""Small.doc"";"
Cache-Control: private
Content-Type: application/msword
"hawkeye parker" <haughki@.gmail.com> wrote in message
news:1184176150.112307.212860@.o11g2000prd.googlegroups.com...
> Yes. Yere's a sample header:
> 4 2 HTTP/1.1 200 OK IEXPLORE (2760) 0x12C8
> "Content-Disposition: attachment;filename=""Small.doc"";"
Those quotes don't belong there...
--
John Saunders [MVP]
hawkeye parker wrote:
> Yes. Yere's a sample header:
> 4 2 HTTP/1.1 200 OK IEXPLORE (2760) 0x12C8
> Date: Mon, 09 Jul 2007 21:22:24 GMT
> Server: Microsoft-IIS/6.0
> X-Powered-By: ASP.NET
> X-AspNet-Version: 2.0.50727
> Content-Length: 19968
> "Content-Disposition:
> attachment;filename=""Small.doc"";"
> Cache-Control: private
> Content-Type: application/msword
I made some test example.
I added Handler1.ashx in project. Code:
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/msword";
byte[] cont =
System.IO.File.ReadAllBytes(context.Server.MapPath("~/MSF.doc"));
System.IO.MemoryStream ms = new System.IO.MemoryStream(cont);
ms.WriteTo(context.Response.OutputStream);
}
public bool IsReusable
{
get
{
return false;
}
}
}
In .aspx file:
<a href="http://links.10026.com/?link=Handler1.ashx">MSF.doc</a>
No more actions. Everything works in IE and Firefox.
Regards,
Mykola
http://marss.co.ua
On Jul 12, 12:10 am, marss <marss...@.gmail.com> wrote:
> hawkeye parker wrote:
>
>
> I made some test example.
> I added Handler1.ashx in project. Code:
> public class Handler1 : IHttpHandler
> {
> public void ProcessRequest(HttpContext context)
> {
> context.Response.ContentType = "application/msword";
> byte[] cont =
> System.IO.File.ReadAllBytes(context.Server.MapPath("~/MSF.doc"));
> System.IO.MemoryStream ms = new System.IO.MemoryStream(cont);
> ms.WriteTo(context.Response.OutputStream);
> }
> public bool IsReusable
> {
> get
> {
> return false;
> }
> }
> }
> In .aspx file:
> <a href="http://links.10026.com/?link=Handler1.ashx">MSF.doc</a>
> No more actions. Everything works in IE and Firefox.
> Regards,
> Mykolahttp://marss.co.ua- Hide quoted text -
> - Show quoted text -
Many thanks Mykola. Yeah, that absolutely works. I'm still having a
problem which I'll address in a separate thread.