changing the size of a textbox in a datagrid?

S

Sean

Hi There,

I would like to find out if I can modify some of the properties of a textbox
within a datagrid?

1. How can modify the width of the fields ? when hit the update button all
of the fields are around 200px wide, I have tried to use "size" but I
receive an error.
2. can I validate the fields in a datagrid say for numeric / currency
datatype ?
3. how can I make a password field in a datagrid?

Sean - Thanks in adavnce for your answer


<asp:DataGrid id="dgUsers" runat="server"
AutoGenerateColumns="False" CellPadding="2" width=400
HeaderStyle-BackColor="purple"
HeaderStyle-ForeColor="White"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True"

EditItemStyle-BackColor="#eeeeee"

OnEditCommand="dgUsers_Edit"
OnUpdateCommand="dgUsers_Update"
OnCancelCommand="dgUsers_Cancel">

<columns>
<asp:EditCommandColumn EditText="Edit Info"
ButtonType="PushButton"
UpdateText="Update" CancelText="Cancel" />
<asp:BoundColumn HeaderText="ID" DataField="CustID"
readonly=true/>
<asp:BoundColumn HeaderText="First Name"
DataField="firstname" />
<asp:BoundColumn HeaderText="Last Name" DataField="lastname"
/>
<asp:BoundColumn HeaderText="Address" DataField="address" />
<asp:BoundColumn HeaderText="Suburb" DataField="suburb" />
<asp:BoundColumn HeaderText="Postcode"
DataField="postcode"/>
<asp:BoundColumn HeaderText="Email Address"
DataField="email" />
</columns>
</asp:DataGrid>
 
K

Ken Cox [Microsoft MVP]

Hi Sean,

You'll want to convert the columns into template columns to change the size
and type of the textbox. Here's how it might look:


<asp:DataGrid id="dgUsers" runat="server" AutoGenerateColumns="False"
CellPadding="2" width="400px"
HeaderStyle-BackColor="purple" HeaderStyle-ForeColor="White"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True" EditItemStyle-BackColor="#eeeeee"
OnEditCommand="dgUsers_Edit"
OnUpdateCommand="dgUsers_Update" OnCancelCommand="dgUsers_Cancel">
<EditItemStyle BackColor="#EEEEEE"></EditItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White"
BackColor="Purple"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit Info"></asp:EditCommandColumn>
<asp:BoundColumn DataField="CustID" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="First Name">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.firstname") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.firstname") %>' Width="194px">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="lastname" HeaderText="Last
Name"></asp:BoundColumn>
<asp:BoundColumn DataField="address"
HeaderText="Address"></asp:BoundColumn>
<asp:BoundColumn DataField="suburb"
HeaderText="Suburb"></asp:BoundColumn>
<asp:BoundColumn DataField="postcode"
HeaderText="Postcode"></asp:BoundColumn>
<asp:BoundColumn DataField="email" HeaderText="Email
Address"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Password">
<ItemTemplate>
<asp:Label id="Label2" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TextBox2" runat="server" Width="186px"
TextMode="Password"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Ken
Microsoft MVP [ASP.NET]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top