Editable textboxes within a datagrid row

2 views
Skip to first unread message

Brock

unread,
Dec 24, 2008, 10:55:03 AM12/24/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I'm using a great book "ASP.NET Data Web Controls" by Scott Mitchell.
In this book I see a screenshot of a datagrid that when the "Edit"
hyperlink button is pressed all the editable fields turn into
textboxes. I wondering how to accomplish this.

Also how do you allow only one row to be chosen? When I hit my edit
button on a row the hyperlink button changes colors, but when I choose
another row the first button is still changed in color? Also when I
hit the button I'm expecting to see "Update" and "Cancel" appear, but
it doesn't. Here is my html if anyone can see any modifications I
should do to accomplish any or all the above.

Thanks!

<asp:datagrid id="dgEvents" runat="server" AutoGenerateColumns="False"
Font-Name="Verdana" Font-Size="X-Small"
HorizontalAlign="Center" ItemStyle-
BackColor="#C0FFC0"
AlternatingItemStyle-BackColor="White" Width="732px"
Height="128px"
AllowSorting="True" BorderColor="PeachPuff"
BorderStyle="Outset"
BorderWidth="10px" CellPadding="10" Font-
Names="Verdana"
BackColor="#FFCC99" Font-Bold="False" Font-
Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False"
DataKeyField="EventID"

OnCommandUpdate="dgEvents_UpdateRow"
OnCommandEdit="dgEvents_EditRow"
OnCommandCancel="dgEvents_CancelRow">

<HeaderStyle BackColor="DarkGreen" HorizontalAlign="Center"
ForeColor="White"
Font-Bold="True"/>

<Columns>

<asp:BoundColumn HeaderText="EventID" DataField="EventID"
ReadOnly="true"/>
<asp:BoundColumn HeaderText="Event" DataField="event" />
<asp:BoundColumn HeaderText="Year" DataField="year" />

<asp:EditCommandColumn CancelText="Cancel" EditText="Edit"
UpdateText="Update">
</asp:EditCommandColumn>

</Columns>

<EditItemStyle BackColor="#FFCC99" Font-Bold="False" Font-
Italic="False"
Font-Overline="False" Font-Strikeout="False" Font-
Underline="False" />

<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#C0FFC0" />
</asp:datagrid>

Cerebrus

unread,
Dec 24, 2008, 11:31:25 AM12/24/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I think this should be :

...
OnUpdateCommand="dgEvents_UpdateRow"
OnEditCommand="dgEvents_EditRow"
OnCancelCommand="dgEvents_CancelRow">

Brock

unread,
Dec 29, 2008, 11:45:37 PM12/29/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Thanks! that got the hyperlink button to switch from Edit to Update &
Canel plus all the editable fields turned into
textboxes. I'm still trying to get two more things formatted: When I
hit my edit button on a row the hyperlink button changes colors, but
when I choose another row the first button is still changed in color?
Also can the size of the textboxes be enlarged from a "default size"?
It would be cool if I could make one of the textboxes 300px x 600px so
all the text would appear. I'm not seeing where in the html the dg
knows to switch to textboxes... is it built into the dg control?
> >         OnCommandCancel="dgEvents_CancelRow">- Hide quoted text -
>
> - Show quoted text -

Cerebrus

unread,
Dec 30, 2008, 10:57:52 AM12/30/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting


On Dec 30, 9:45 am, Brock <wade.br...@yahoo.com> wrote:
> When I hit my edit button on a row the hyperlink button changes colors,
> but when I choose another row the first button is still changed in color?

Been a while since I've worked with the DataGrid, but if it's
happening it must be the normal behaviour of hyperlinks. Elementary
HTML/CSS ! ;-)
To fix it you would need to override the CSS for anchors, specifically
the visited pseudo-class, setting the font-decoration property.

> Also can the size of the textboxes be enlarged from a "default size"?
> It would be cool if I could make one of the textboxes 300px x 600px so
> all the text would appear. I'm not seeing where in the html the dg
> knows to switch to textboxes... is it built into the dg control?

Again, you need to override the default behaviour and provide your own
EditItemTemplate, with fixed textbox widths.
Reply all
Reply to author
Forward
0 new messages