question

SumeetDeshpande-3071 avatar image
0 Votes"
SumeetDeshpande-3071 asked LanHuang-MSFT edited

i want lot name (type in text box lot name) in 2nd row in GridView1

i want lot name (type in text box lot name) in 2nd row in GridView1
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-12">
<div class="form-group">
<label>Lot Name <span style="color:red;">*</span></label>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="form-group">
<asp:TextBox ID="txt_Lot_Name" runat="server" CssClass="form-control" />

                               </div>
                             </div>
                             <div class="col-md-2 col-sm-2 col-xs-12">
                               <div class="form-group">
                                 <label>Upload Excel File <span style="color:red;">*</span></label>
                               </div>
                             </div>
                             <div class="col-md-4 col-sm-4 col-xs-12">
                               <div class="form-group">
                               <asp:FileUpload ID="FileUpload1" runat="server" />
     <%--<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />--%>
      
                                   
     
                               </div>
                             </div>

                         </div>


                       <asp:GridView ID="GridView1" runat="server" CssClass="table table-striped table-bordered table-hover dataTable no-footer"  AutoGenerateColumns="False" ShowFooter="True" OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True" PageSize="20">
                           <AlternatingRowStyle Width="100%" />
                    <Columns>
                        <asp:TemplateField HeaderText="Sr No">
                            <EditItemTemplate>
                                <asp:TextBox ID="txtSr_no" runat="server" Text='<%# Bind("Sr_no") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                     <%# Container.DataItemIndex + 1 %>
                     <asp:HiddenField ID="hf_val" runat="server" />
                 </ItemTemplate>
                            <ItemStyle Width="20px" />
                        </asp:TemplateField>
                      <asp:BoundField DataField="Lot_Name" HeaderText="Lot Name" /> ----(here lot_name update in filed)
                        <asp:BoundField DataField="REGDNUM" HeaderText="REGDNUM" />
                        <asp:BoundField DataField="AGENCY_PHONE_NUMBERS" HeaderText="AGENCY PHONE" />
                        <asp:BoundField DataField="CHASSI_NO" HeaderText="CHASSI NO" />
                        <asp:BoundField DataField="CUSTOMER_NAME" HeaderText="CUSTOMER NAME" />
                        <asp:BoundField DataField="MAKE" HeaderText="MAKE" />
                        <asp:BoundField DataField="ENGINE_NUM" HeaderText="ENGINE NUM" />
                        <asp:BoundField DataField="AGREEMENT_NO" HeaderText="AGREEMENT NO" />
                        <asp:BoundField DataField="FIN_COMPANY_NAME" HeaderText="FIN_COMPANY_NAME" />
                        <asp:BoundField DataField="BRANCH" HeaderText="BRANCH" />
                        <asp:BoundField DataField="ARM_NAME_AND_MOBILE_NUMBER" HeaderText="ARM_NAME_AND_MOBILE_NUMBER" />
                        <asp:BoundField DataField="ABM_NAME_AND_MOBILE_NUMBER" HeaderText="ABM NAME AND MOBILE NUMBER" />
                        <asp:BoundField DataField="RRM_NAME_AND_MOBILE_NUMBER" HeaderText="RRM NAME AND MOBILE NUMBER" />
                        <asp:BoundField DataField="RBM_NAME_AND_MOBILE_NUMBER" HeaderText="RBM NAME AND MOBILE NUMBER" />
                    </Columns>
                  </asp:GridView>

I want to save this gridview data To sql table On Button Click

How To Do So..? all the data in sql database


dotnet-aspnet-general
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @SumeetDeshpande-3071,

The openspec-* tags are dedicated to supporting issues related to open specifications. You can find open specifications here https://docs.microsoft.com/en-us/openspecs/. Since your question does not pertain to one of these specifications, I've removed the openspecs tag and added the dotnet-aspnet-general tag. Hopefully this will get your post the proper attention.

Jeff McCashland
Microsoft Open Specifications

0 Votes 0 ·

1 Answer

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered LanHuang-MSFT edited

Hi @SumeetDeshpande-3071,
From your description and the code you provided, I think you want to save the updated lot name to the database.
I recommend you to use the OnRowEditing and OnRowUpdating methods.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.gridview.onrowediting?view=netframework-4.8
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.gridview.onrowupdating?view=netframework-4.8
You can refer to the example below:

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="6" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">  
      <Columns>  
                 <asp:TemplateField>  
                     <ItemTemplate>  
                         <asp:Button ID="btn_Edit" runat="server" Text="Edit" CommandName="Edit" />  
                     </ItemTemplate>  
                     <EditItemTemplate>  
                         <asp:Button ID="btn_Update" runat="server" Text="Update" CommandName="Update"/>  
                         <asp:Button ID="btn_Cancel" runat="server" Text="Cancel" CommandName="Cancel"/>  
                     </EditItemTemplate>  
                 </asp:TemplateField>  
                  <asp:TemplateField HeaderText="Sr_no">  
                     <ItemTemplate>  
                         <asp:Label ID="lbl_ID" runat="server" Text='< % # Ev al("Sr_no") %>'></asp:Label>  
                     </ItemTemplate>  
                 </asp:TemplateField>  
                    <asp:TemplateField HeaderText="Lot_Name">  
                     <ItemTemplate>  
                         <asp:Label ID="lbl_Name" runat="server" Text='< % # Ev al("Lot_Name") %>'></asp:Label>  
                     </ItemTemplate>  
                     <EditItemTemplate>  
                         <asp:TextBox ID="txt_Name" runat="server" Text='< % # Ev al("Lot_Name") %>'></asp:TextBox>  
                     </EditItemTemplate>  
                 </asp:TemplateField>  
                  <asp:TemplateField HeaderText="REGDNUM">  
                     <ItemTemplate>  
                         <asp:Label ID="REGDNUM" runat="server" Text='< % # Ev al("REGDNUM") %>'></asp:Label>  
                     </ItemTemplate>  
                 </asp:TemplateField>                       
             </Columns>  
         </asp:GridView>  
          
   </asp:GridView>  

  string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
         SqlConnection con;
         SqlDataAdapter adapt;
         DataTable dt;
         protected void Page_Load(object sender, EventArgs e)
         {
             if (!IsPostBack)
             {
                 ShowData();
             }
         }
         //ShowData method for Displaying Data in Gridview  
         protected void ShowData()
         {
             dt = new DataTable();
             con = new SqlConnection(cs);
             con.Open();
             adapt = new SqlDataAdapter("Select * from Test", con);
             adapt.Fill(dt);
             if (dt.Rows.Count > 0)
             {
                 GridView1.DataSource = dt;
                 GridView1.DataBind();
             }
             con.Close();
         }
       protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
         {
             //NewEditIndex property used to determine the index of the row being edited.  
             GridView1.EditIndex = e.NewEditIndex;
             ShowData();
         }
         protected void GridView1_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)
         {
             //Setting the EditIndex property to -1 to cancel the Edit mode in Gridview  
             GridView1.EditIndex = -1;
             ShowData();
         }

239936-image.png
239970-1234.gif
Best regards,
Lan Huang


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (29.2 KiB)
1234.gif (182.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.