|
Hi all
I have a problem with selected items I do this :
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
}
I have noticed the IsDirty is allways true for each item. What am I doing wrong?
Thanx in advance
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
I've just tried this out, thinking it must be something simple but I have exactly the same problem.
In addition, if you set it to AutoPostBack and give it a handler for "SelectedIndexChanged" (because that's how the example in MSDN works)then it posts back but doesn't call the event.
Bizarre.
Have you thought about using normal Checkboxes? If you need to bind it, try a DataRepeater. A bit naff but it's the best I've got.
Paul
|
|
|
|
|
Paul Riley wrote:
I've just tried this out, thinking it must be something simple but I have exactly the same problem.
Guess you made the same mistake as me
I found out what I was doing wrong. In my page load event i was creating the checkboxes from an enum, BUT page load gets fired again before button click is handled (something I guess I have to keep in mind all the time). This was my solution:
private bool setup = true;
private void Page_Load(object sender, System.EventArgs e)
{
try
{
setup = (bool) ViewState["setup"];
}
catch (System.NullReferenceException){}
if (setup) SetupPage();
}
private void SetupPage()
{
setup = false;
ViewState["setup"] = setup;
}
Read setup as setup? (Do you want to setup?).... It looks a bit in reverse, but my logic prefers it. Maybe I should call it dosetup?
Hope this is the same problem as you have, else I'm clueless.
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
leppie wrote:
Hope this is the same problem as you have, else I'm clueless.
Similar. I had it Databound at the bottom of a page I'd already written and this.Databind() (too lazy to databind 8 dropdownlists and a textbox) in the Page_Load.
You have no idea how many times I've fallen into this trap of Page_Load running first. It seems so illogical.
Paul
|
|
|
|
|
Paul Riley wrote:
You have no idea how many times I've fallen into this trap of Page_Load running first. It seems so illogical.
Depends how you look at it, this is probably some nasty remains from ASP, and hopefully in ASP.NET v2, us developer wont have to write a single line of ASP code.
Currently, I'm succeeding in the site I'm doing without writing a single line of ASP code in html , besides the code inserted automatically by the VS designer. I find it is difficult to keep 2 sides in mind all the time.
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
leppie wrote:
Depends how you look at it, this is probably some nasty remains from ASP
Well, ASP didn't have events, so I don't see how it can be. Someone has sat there and considered this and decided that Page_Load should execute every time and always before any event code. That makes no sense. When the button is pressed, the event that relates to that should execute; then the page should be loaded.
leppie wrote:
hopefully in ASP.NET v2, us developer wont have to write a single line of ASP code.
I don't get this. If you don't want to do any processing at the server side then there's no need to use ASP(.NET) at all.
What does your site do that doesn't require much code? I'm currently writing a sign-up site for a tournament (we're expecting upwards of 500 people, some will be bunched into teams of 7 or more, some will need to be able to sign up in small groups, find other small groups and then combine them into a team).
I've been doing a lot of coding for that.
To be fair, I overcomplicated things by doing all database processing in WebServices, so that I can later write programs to do the same thing, but even without that it would be a lot of code.
Paul
|
|
|
|
|
Paul Riley wrote:
leppie wrote:
hopefully in ASP.NET v2, us developer wont have to write a single line of ASP code.
OK, maybe I understood it wrong, but I thought that ASP code, is embedded ASP commands and syntax within HTML, where I am purely trying to "push" everything to the client via ASP.NET in C#.
I do totally agree with you! I would prefer everything server-side exclusively.
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
Sorry, I missed you point completely there, didn't I?
In that case I'm with you completely; the only code I have embedded in the HTML is databinding stuff which really does belong there. It'd be evil if you had to look back to your code to see what data was bound to what control.
Paul
|
|
|
|
|
Paul Riley wrote:
the only code I have embedded in the HTML is databinding stuff which really does belong there
I just get values from a dataset No need to even to do databinding in HTML.
Infact, Templated Databound Controls looks waaaaaaayyyyy to complicated for my needs, but it mite be usefull for the control designer (who wishes to make distributable controls). BTW, does a property need a special attribute to become databindable?
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
leppie wrote:
I just get values from a dataset No need to even to do databinding in HTML.
Very true and I did my first site that way, but DataBinding is very powerful and can remove tons of code from the CodeBehind.
For example, if you want to build a DropDownList from a DataSet, you can run through the dataset and add the items in a loop. Or you can drop the DataSet and the DropDownList onto your page, go into the Data properties, select the dataset, the value field and the text field and you're done (except one line of code to tell it when to DataBind).
Not too much of a saving if you only have one DropDownList. But I have one page with eight DropDownLists all containing a list of players for a team, so the team can assign a captain and the 7 players.
In that scenario, I only need to drop one DataSet onto the form and I can bind all 8 DropDownLists to it. A single this.DataBind() and it's all done.
leppie wrote:
BTW, does a property need a special attribute to become databindable?
Yeah, I think it's Bindable(true). I haven't written a custom control that needs databinding as yet but it looks simple enough.
Paul
|
|
|
|
|
Paul Riley wrote:
Yeah, I think it's Bindable(true). I haven't written a custom control that needs databinding as yet but it looks simple enough.
It'll try that Thanx! Unfortunately mine is all custom rendering , basically an object and webcontrol in one. So my properties mite just need that
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
Incidentally, bound datagrids are even cooler. I have one page that needs to display a list of players in a dataset.
The first column needs to contain the name which is also a link to another page, passing the player id as a parameter.
The second column needs to contain the email address which is also a mailto: link.
The third column should be a location. It took me about 15 minutes to knock that together with the following code:
<asp:datagrid id=dgPlayer runat="server" Width="100%" DataMember="Player" DataSource="<%# dsPlayer %>" AutoGenerateColumns="False" DataKeyField="PlayerID">
<HeaderStyle Font-Bold="True"></HeaderStyle>
<Columns>
<asp:TemplateColumn ItemStyle-Width="50%">
<HeaderTemplate>
Player <i>(Click to Edit)</i>
</HeaderTemplate>
<ItemTemplate>
<a href='editplay.aspx?guid=<%# DataBinder.Eval(Container.DataItem, "PlayerID" ) %>'>
<%# DataBinder.Eval(Container.DataItem, "FullName" ) %>
</a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn ItemStyle-Width="25%">
<HeaderTemplate>
Email
</HeaderTemplate>
<ItemTemplate>
<a href='mailto:<%# DataBinder.Eval(Container.DataItem, "Email" ) %>'>
<%# DataBinder.Eval(Container.DataItem, "Email" ) %>
</a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Location" HeaderText="Location" ItemStyle-Width="25%"></asp:BoundColumn>
</Columns>
</asp:datagrid> It might have taken me a hell of a lot longer to do this using code. DataBinding does seem complicated when you first come to play with it but, like most things in .NET, once you've done it a couple of times it's great.
Paul
|
|
|
|
|
You can even just bind the data without that code, by just using the Property Builder and you get this :
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 10px; POSITION: absolute; TOP: 11px" runat="server" Width="720px" Height="247px" DataSource="<%# dataSet11 %>" DataKeyField="ID" AllowSorting="True" DataMember="Users">
</asp:DataGrid>
</form>
</body>
</HTML>
and in the page load event:
oleDbDataAdapter1.Fill(dataSet11.Users);
DataBind();
My HTML pages look similar to this. Dump one container control, and preform all the rest of tasks at server-side I must say the DtaGrid is extremely well designed, but can be a bit limiting, hence my need to have made a custom control.
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
leppie wrote:
by just using the Property Builder and you get this :
Unfortunately the <pre> tag isn't very smart when it comes to asp: tags. So I can't actually read what you've written there (I had to copy to notepad and do a few mass replaces)
leppie wrote:
I must say the DtaGrid is extremely well designed, but can be a bit limiting, hence my need to have made a custom control.
Limiting how? I haven't found anything I can't do with a datagrid yet (at least nothing that I'd want to do )
Paul
|
|
|
|
|
Paul Riley wrote:
Limiting how? I haven't found anything I can't do with a datagrid yet (at least nothing that I'd want to do )
It can only hold a row of data Sometimes you need to communicate multiple lines of info to the client if the data is too "wide" for the page. Take a very simple forum as an example. OOhh just had an idea, a forum of one-liners . I'm getting tired
CP should really have an IRC server or some chat rooms that are logged and moderated, taking useful snippets and info and adding that to a sticky FAQ thread in each forums. OK, maybe I'm just asking for wwaaayyy too much! I would assume the Lounge would be chaos.
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
leppie wrote:
Sometimes you need to communicate multiple lines of info to the client if the data is too "wide" for the page.
Gotcha. It's true that DataBinding a DataGrid falls apart there (and it probably shouldn't - most reporting programs will let you leave a column blank if it's the same as the row before), but you can still do this easily by code. Or if you really want to databind it for some reason, just build a normal table using a DataRepeater.
The forum example in particular could be done easily using a DataRepeater.
And please, forget you even considered the chat room idea, I spend far too much time here already
Paul
|
|
|
|
|
Any one who have any idea of any IDE for for developing application for ASP??
|
|
|
|
|
Visual Interdev is cool, especially as it works nicely with SQL Server (or Access) as Microsoft built them all.
The following statement about your geekness is true. The previous statement about your geekness is false.
|
|
|
|
|
What else .. but Visual Studio;P
|
|
|
|
|
|
Hi,
if I have javascript function:
function doWork()
{
//some important work to do
}
ho can I retrieve function name and store it in variable INSIDE that function????? I tried to do this:
function doWork()
{
//some important work to do
var func_name ;
func_name = this.name ;
}
but nothing...
is this possible and how?
|
|
|
|
|
Thats an interesting problem...why do you need to do this...maybe there is another way...?
I dunno if this will work but you can try this...
So long as the function is defined as follows and not externally (i think)
<script id='test' language='jscript'>
function ExecFunc(){
alert('Do something useful');
}
</script>
You can try extracting whatever is between the script tags using document.all.test.text parse the entire text for only function names and pass the variable strings to eval function when you need them exectued...
HTH
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
<vent>
Is it me, or is the web still the last thing looked at for innovations?
I mean, really... Would it be so hard for MS to include a decent way for controls placed onto a form to be resized as the page gets resized without having to resort ot all kinds of javascript hacks?
|
|
|
|
|
Ray Cassick wrote:
Would it be so hard for MS to include a decent way for controls placed onto a form to be resized as the page gets resized without having to resort ot all kinds of javascript hacks?
You don't need JavaScript hacks Ray. Use CSS, it does it quite fine.
|
|
|
|
|
Paul Watson wrote:
You don't need JavaScript hacks Ray. Use CSS, it does it quite fine.
Ok, I'm open.. can you point me towards any examples?
Sorry for the nasty rant, but I was really kind of p*ssed that I could not use some simple VB (or C# for that matter to resize a control because aparently the page does not fire a resize event...
I thought webfroms were supposed to make things oh so much simpler... MS Finally made it easy to code windows forms that resize controls without writing any code, and I stil can't even write code on a web page in VB to do this. UGH!
|
|
|
|