newbie--datalist question

  • Thread starter Thread starter SStory
  • Start date Start date
S

SStory

I have the ASP Unleased book--of course all code. So it doesn't help me tie
it to the VSNET IDE easily--to know what I have to do and what is done for
me.

I am trying to make a simple datalist that will get 3 fields from a database
plus the Identity field--so 4 total--identity field won't be shown.

I dropped a datalist on the webform.. Found the Edit Template menu
item...went into edit template mode..
I dragged some Web forms controls in each of the various templates. I set
style background colors etc.

In this design form all three controls (webform labels) are on one line, but
the show up with a large amount of space between each item (vertically)
Why?
I do have an edititem template that is larger and has multiple lines, but I
thought that that only mattered when it was to do an edit.

I made a linkbutton Edit in the ItemTemplate

I set its commandname to edit

in my book he had to do a OnEditCommand=dlstAuthors_EditCommand in his
example...
with the IDE, I don't have to do that or do I.

I am connecting to SQL in code not through a sqlconnection control--does
that matter?

Due to this I had to go into my HTML code and place the text='<%#
container.dataitem("whatever")%>
Manually. Should I have done it this way... Is there a way to do that in
the IDE? Or will it only work if there is a SQL Connection control on the
form? What is the best way?

Anyhow in the datalist1_editcommand sub
I placed
datalist1.edititemindex=e.item.itemindex
binddatalist 'this just hits the sql server for the data

But click edit didn't bring up the edit item as I had imagined.

Can anyone tell me why my formatting for each item has all this vertical
space between items, but in the template I see no reason why?

And why doesn't my edit command work?

Thanks
 
SStory,
In this design form all three controls (webform labels) >are on one line, but
the show up with a large amount of space between each item
(vertically)
Why?

You should look at the HTML to figure out the formatting.
in my book he had to do a >OnEditCommand=dlstAuthors_EditCommand in his
example...
with the IDE, I don't have to do that or do I.

Contrary to the opening pages of any beginner book, the drag'n'drop
features of the IDE will not take you very far. The
OnEditCommand=dlsAuthor_EditCommand is what associates Edit clicks
within the DataList with an event handler, in this case Sub
dlsAuthors_EditCommand (bottom of page 539).

The SQLConnection control on the form is a simple way to have the IDE
write some of you code for you. There are a bunch of different ways to
connect to a db. Whatever works, works.

To make the edit work, you have to have CommandName="edit" in the
control, "OnEditCommand = dlsAuthor_EditCommand" in the DataList, and
"datalist1.edititemindex=e.item.itemindex" within the sub routine,
making sure that the datalist1 value is the same as the name of your
datalist (dlstAuthors in the book).

I hope this helps,
Barry
 
Thanks for the answers Barry.

So this means if I had placed a SQL connection on the form it would have done this for me, but since I connected by code I have to do the On command statements in HTML..

Here's the code(on down below).. Why does it space so far apart between each item ( I added the pre tags to show the code in html emailer)?

what I want for example is

Edit Nashville, TN 30105
Edit Camden, AL 30306
should be simple

Then the edit form would be bigger like
City [text box]

State [drop down]

Zip [text box]
Update Delete Cancel

Any how it looks more like
Edit Nashville, TN 30105




Edit Camden, AL 30306
<pre> <asp:datalist id="dlstRepAvailLocations" runat="server" height="124px">
<selecteditemtemplate>
<asp:label id="Label20" runat="server" width="76px" text='<%# Container.dataitem("rploc_City")%>'>
</asp:label>,&nbsp;
<asp:label id="Label21" runat="server" width="33px" text='<%# Container.dataitem("rploc_State")%>'>
</asp:label>&nbsp;
<asp:label id="Label22" runat="server" text='<%# Container.dataitem("rploc_ZipCode")%>'>
</asp:label>
</selecteditemtemplate>
<itemtemplate>
<asp:linkbutton id="lnkEdit" runat="server" commandname="edit">Edit</asp:linkbutton>
<asp:label id="lblDLCity" runat="server" width="76px" text='<%# Container.dataitem("rploc_City")%>'>
</asp:label>,
<asp:label id="lblDLState" runat="server" width="33px" text='<%# Container.dataitem("rploc_State")%>'>
</asp:label>&nbsp;
<asp:label id="lblDLZipCode" runat="server" text='<%# Container.dataitem("rploc_Zipcode")%>'>
</asp:label>
</itemtemplate>
<alternatingitemtemplate>
<asp:linkbutton id="lnkEditAlt" runat="server" commandname="edit">Edit</asp:linkbutton>&nbsp;
<asp:label id="Label17" runat="server" width="76px" text='<%# Container.dataitem("rploc_City")%>'>
</asp:label>,
<asp:label id="Label18" runat="server" width="33px" text='<%# Container.dataitem("rploc_State")%>'>
</asp:label>&nbsp;
<asp:label id="Label19" runat="server" text='<%# Container.dataitem("rploc_ZipCode")%>'>
</asp:label>
</alternatingitemtemplate>
<edititemtemplate>
<p>
<asp:label id="Label23" runat="server" width="68">City</asp:label>
<asp:textbox id="txtEditCity" runat="server" width="115px" text='<%# Container.dataitem("rploc_City")%>'>
</asp:textbox>
<asp:requiredfieldvalidator id="Requiredfieldvalidator1" runat="server" cssclass="VALERRMSG" errormessage="City Required"></asp:requiredfieldvalidator><br>
<asp:label id="Label24" runat="server" width="69">State</asp:label>
<uc1:states id="States1" runat="server"></uc1:states><br>
<asp:label id="Label25" runat="server" width="69px">Zip Code</asp:label>
<asp:textbox id="txtEditZipCode" runat="server" width="70px" text='<%# Container.dataitem("rploc_City")%>'>
</asp:textbox>
<asp:requiredfieldvalidator id="Requiredfieldvalidator5" runat="server" cssclass="VALERRMSG" errormessage="Zip Code Required"></asp:requiredfieldvalidator></p>
<p align="center">
<asp:linkbutton id="lnkUpdate" runat="server" commandname="update">LinkButton</asp:linkbutton>&nbsp;|
<asp:linkbutton id="lnkDelete" runat="server" commandname="delete">Delete</asp:linkbutton>&nbsp;|
<asp:linkbutton id="lnkCancel" runat="server" commandname="cancel">Cancel</asp:linkbutton></p>
</edititemtemplate>
</asp:datalist></pre>

At first I was using grid layout but then switched and threw this datalist into a table cell on the left side.
I have project I need to do within a month--pretty big--I really need to figure this and datagrids out.
Probably work similar.

Thanks in Advance,

Shane
 
The SQL Connection method has no impact on whether or not you have to
use OnCommand. These HTML-based handlers are required regardless.

I noticed a couple of <p> tags in your editItemTemplate. If you need a
line break, try removing them or replacing them with <br> tags.

Barry
 
That is surprising I would have thought that an IDE would do that sort of
redundant stuff for you.

My edititem is fine, except it won't appear, just shows the header above the
datalist and blanks out the datalist... ?

buy my itemtemplate has no br's but still has a ton of space between each
item.. I cannot see why.

Thanks
 
Back
Top