Click here to Skip to main content
16,013,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

From a week I am fighting with this requirement,Please can anyone help me.

C#
<asp:DetailsView ID="dview" runat="server" Height="250px" Width="250px" 
            AutoGenerateRows="False" onitemcommand="dview_ItemCommand" DataSourceID="sds1" 
                            EmptyDataText="No records" oniteminserting="dview_ItemInserting">
            
            <Fields>                
                <asp:TemplateField HeaderText="Name">                
                    <ItemTemplate>
                        <asp:TextBox ID="t1" runat="server" Text='<%# Bind("CustomerName") %>'></asp:TextBox>
                    </ItemTemplate>
                    <EditItemTemplate><asp:TextBox ID="t1" runat="server" ></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Address">
                    <ItemTemplate>
                        <asp:TextBox ID="t2" runat="server" Text='<%# Bind("CompanyName") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>                
                <asp:TemplateField HeaderText="Phone">
                    <ItemTemplate>
                        <asp:TextBox ID="t3" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:ButtonField Text="SAVE" CommandName="InsertButton" />
            </Fields>
            
        </asp:DetailsView>
         <asp:sqldatasource id="sds1"  
          selectcommand="SELECT CustomerName,CompanyName,City from Customers"
          connectionstring="server=localhost;database=Test;integrated security=SSPI"
          runat="server">
        </asp:sqldatasource>



Here I attached datasource so the detailsview so records from table is displaying in the textboxes of detailsview.But now I need to display empty Textboxes so that I can enter the data and then on Clicking SAVE button to save data entered inthe textboxes to the database.

Could you please help me the design to achieve like this.

Hope You got my question.
Posted
Updated 5-Jul-12 22:27pm
v2

1 solution

you should use DetailsView control that will give presentation rowwise as you like.
ASP.NET
<asp:DetailsView ID="editProfile" runat="server" Height="550px" Width="625px" AutoGenerateRows="false"
          OnItemCommand="editProfile_ItemCommand">
          <Fields>
              <asp:TemplateField HeaderText="Profile Id">
                  <ItemTemplate>
                      <asp:TextBox ID="txtProfileId" runat="server" Text='<%# Bind("Profile_Id") %>' ReadOnly="true"></asp:TextBox>
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText="User Id">
                  <ItemTemplate>
                      <asp:TextBox ID="txtUserId" runat="server" Text='<%# Bind("User_Id") %>' ReadOnly="true"></asp:TextBox>
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText="Name">
                  <ItemTemplate>
                      <asp:TextBox ID="txtUserName" runat="server" Text='<%# Bind("User_Name") %>'></asp:TextBox>
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText="Mobile No">
                  <ItemTemplate>
                      <asp:TextBox ID="txtMobileNo" runat="server" Text='<%# Bind("Mobile_No") %>'></asp:TextBox>
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:ButtonField Text="Update Profile" CommandName="updateButton" />
          </Fields>
          <HeaderTemplate>
              <%# Eval("User_Id") %>
          </HeaderTemplate>
      </asp:DetailsView>

Now on ItemCommand event of detailsview find the button and perform task.
 
Share this answer
 
v3
Comments
palcordis 5-Jul-12 3:55am    
I tried but I am not getting the row wise design of controls.
Cannot we achieve in Gridview?

Any further help is needed.
Thank you,
Raje_ 5-Jul-12 7:25am    
i have improved the solution try this code that is given above.
palcordis 5-Jul-12 8:47am    
Thank you Rajesh,

Excellent work,Its working fine.
One more question.If I run the Detailsview it shoud open with empty controls like web form then I need to enter data in textboxes and Save the data to database after clicking SAVE button.
Here is the code given by you

<asp:DetailsView ID="editProfile" runat="server" Height="374px" Width="495px" AutoGenerateRows="false"
OnItemCommand="editProfile_ItemCommand">
<fields>
<asp:TemplateField HeaderText="Name">
<itemtemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Bind("P_Name") %>'>


<asp:TemplateField HeaderText="Address">
<itemtemplate>
<asp:TextBox ID="txtPhyAddress" runat="server" Text='<%# Bind("P_Add") %>'>


<asp:TemplateField HeaderText="Phone">
<itemtemplate>
<asp:TextBox ID="txtPhone" runat="server" Text='<%# Bind("P_Phone") %>'>


<asp:ButtonField Text="SAVE" CommandName="updateButton" />

<HeaderTemplate>
<%# Eval("User_Id") %>
</HeaderTemplate>


Could you tell me the furthur steps.

Thank you,
Raje_ 5-Jul-12 13:36pm    
yes palcordis you can do it, place your textbox in EditItemTemplate and in ItemTemplate put the controls that you want to display when detailsview cotrol loads.
best of luck.
palcordis 6-Jul-12 2:37am    
Yes I tried Rajesh but I am not getting this .I dont know what is the problem.If I run the Page nothing is showing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900