5
Answers

Datagrid problem

Photo of yokzu

yokzu

13y
3.2k
1
Hi,
I am using a datagri control on my web page. I edit, update and cancel on this control.
------------------------
<asp:DataGrid ID="DataGrid1" RUNAT="server"  AutoGenerateColumns="False" 
  OnUpdateCommand="cmd_update" OnEditCommand="cmd_edit"
  OnCancelCommand="cmd_cancel">
-------------------------

The problem is when I click the edit button, textbox's showing at rows which I want to edit. No problem at this point. But This textbox's width is too long and I want to edit this textbox's lengths. How may I do that?

Answers (5)

0
Photo of Sharad Gupta
NA 19.6k 4.3m 12y
1-first create a database table ,in which write field like id,name salary  
2-After it stablish connection.
3-Take a asp control kike repeter ,datagrid etc.
4-And write that code into source code file;

<ItemTemplate>
    </ItemTemplate>
    <asp:Textbox ID ="ti" runat="server" width="60px"><%Eval("id") %></asp:Textbox>
    </asp:Repeater>
0
Photo of sathish kumar
NA 119 115k 12y

Just try like below......

<TemplateField HeaderText='name">
<ItemTemplate>
  <asp:textbox="txtname" runat="server" width="70px"></textbox>
</ItemTemplate>
</TemplateField>
0
Photo of Ajay Patel
NA 142 141.6k 12y
If you are using edit Item template then you can set your textbox's width from aspx.
but when you use bound fields then you can esize textboxes from edit Command by,

  ((Textbox)(e.rows[e.editIndex].cell[0].control[0])).width = 100px;

try this....
0
Photo of yokzu
NA 306 0 13y
Thanks for your repley Senthilkumar,
But there is no textbox control on my code. I mean When I click the "edit", textbox's appears automatically.

-------------------------------------------------------------------
    <asp:DataGrid ID="DataGrid1" RUNAT="server"  AutoGenerateColumns="False" 
                    OnUpdateCommand="komut_update" OnEditCommand="komut_edit"
    OnCancelCommand="komut_cancel" CellPadding="4" ForeColor="#333333" GridLines="None" Width="400px" >

        <AlternatingItemStyle BackColor="White" />

    <Columns>
    <asp:EditCommandColumn EditText="Düzenl"  CancelText="Vazgeç" UpdateText="Güncelle" HeaderText="Düzenle" />
    <asp:BoundColumn HeaderText="ID" DataField="ID" ReadOnly="false"  />
    <asp:BoundColumn HeaderText="IP" DataField="IP" />

    </Columns>

    <EditItemStyle BackColor="#2461BF" Height="50"  />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <ItemStyle BackColor="#EFF3FB" Width="100" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    </asp:DataGrid>
-------------------------------------------------------------------

When I change the "editItemStyle" propeties above, I can change somethings but not textbox's.
0
Photo of Senthilkumar
NA 15.2k 2.4m 13y
Hi,

You can restrict the width of the text box in either way

<asp:TextBox ID="txtIPAddress" runat="server" Width="85px"></asp:TextBox>
<asp:TextBox ID="txtIPAddress" runat="server" style="width:85px;"></asp:TextBox>

If you want to maintain this size in many problems then you are adivsed to do through css

.TextBox85
{
        width:85px;
}

<asp:TextBox ID="txtIPAddress" runat="server" CssClass="TextBox"></asp:TextBox>


If you want to set the size at the time of editing then edit command,
you can find the control and set the width to it.

TextBox txtIPAddress = (TextBox) e.FindControl("txtIPAddress");
txtIPAddress.Width  = system.web.ui.webcontrols.unit.pixel(85)

Hope this will help you.