-1

I want to display the TextBox inside a details view in a new line as i am fetching the data from database and trying to make a Form

How do i do this

enter image description here

code

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px" 
    AutoGenerateRows="False" GridLines="None">
   <Fields>
   <asp:TemplateField >
                <ItemTemplate>
                    <asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField >
                <ItemTemplate>
                    <asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Fields>
           </asp:DetailsView>

Please someone help?

vini
  • 4,657
  • 24
  • 82
  • 170

3 Answers3

1

You can't

The DetailsView control is based on table-views

If you want to implement your custom design you would have to use the FormView control and use the correct templates. Example:

<asp:FormView runat="server" AllowPaging="true" ID="formView">
    <ItemTemplate>
        <%--customize the html--%>
    </ItemTemplate>

However consider that the DetailsView control automatically creates the design for you, including controls in different modes like Edit, Insert and ReadOnly. When using the FormView control, you will have to provide templates for each mode

Jupaol
  • 21,107
  • 8
  • 68
  • 100
  • so a formview would be better? – vini Oct 01 '12 at 09:55
  • A `FormView` will give you **full control** over the final HTML. At the cost to have to write it manually for each template. Consider the trade-offs for your specific case – Jupaol Oct 01 '12 at 09:57
1

try this

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px" 
AutoGenerateRows="False" GridLines="None">
    <Fields>
        <asp:TemplateField >
            <ItemTemplate>
                <table>
                    <tr>
                        <td><asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox></td>
                        <td><asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label></td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:TemplateField>        
    </Fields>
</asp:DetailsView>

** i have put both data inside single templatefield

th1rdey3
  • 4,176
  • 7
  • 30
  • 66
  • works well !! :) but what if i want to put a textbox right below another in this form what code should i use? – vini Oct 01 '12 at 10:00
  • @vini add another row to the table and put the textbox on that row. or you can just add another Templatefield. – th1rdey3 Oct 01 '12 at 10:02
0

Try putting ItemFields in Table Row as follow...

   <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="520px"      AutoGenerateRows="False" GridLines="None"> 
       <Fields>
       <table>
             <tr>
                <td>
                    <asp:TemplateField >    
                                       <ItemTemplate>   <asp:TextBox ID="txtDtaLineDtchecked" runat="server" Text='<%# Bind("DtaLineDtChecked") %>' ></asp:TextBox>                 </ItemTemplate>
                </asp:TemplateField>
               </td>
                <td>
                   <asp:TemplateField >
                                      <ItemTemplate> <asp:Label ID="lblDtaLineUsermatch" runat="server" Text='<%# Bind("DtaLineUserMatch") %>' ></asp:Label>                 </ItemTemplate>             
                   </asp:TemplateField>
                </td>
           </tr>
      </table>
      </Fields>
 </asp:DetailsView> 
Amol Kolekar
  • 2,307
  • 5
  • 30
  • 45