Akhter HUssain

Akhter HUssain

  • 720
  • 1.3k
  • 101.2k

How to updateDeleteinsert row after retrieving data in GV?

Aug 14 2019 12:02 AM
I want to Update|Delete|Insert row into gridview after retrieving data from database into gridview in Master Detail Form..
 
I am inserting|Deleting|Updating data into gridview using viewstate  
here is my html 
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BalePack.aspx.cs" Inherits="WebApplication1.BalePack" %>  
  2.   
  3. <!DOCTYPE html>  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head runat="server">  
  7.   
  8.     <style>  
  9.         .grdContent  
  10.         {  
  11.             width: 80%;  
  12.             border: solid 2px black;  
  13.             min-width: 80%;  
  14.         }  
  15.         .header  
  16.         {  
  17.             background-color: #646464;  
  18.             font-family: Arial;  
  19.             color: White;  
  20.             border: none 0px transparent;  
  21.             height: 25px;  
  22.             text-align: center;  
  23.             font-size: 16px;  
  24.         }  
  25.         .rows  
  26.         {  
  27.             background-color: #fff;  
  28.             font-family: Arial;  
  29.             font-size: 14px;  
  30.             color: #000;  
  31.             min-height: 25px;  
  32.             text-align: left;  
  33.             border: none 0px transparent;  
  34.         }  
  35.         .rows:hover  
  36.         {  
  37.             background-color: #ff8000;  
  38.             font-family: Arial;  
  39.             color: #fff;  
  40.             text-align: left;  
  41.         }  
  42.         .selectedrow  
  43.         {  
  44.             background-color: #ff8000;  
  45.             font-family: Arial;  
  46.             color: #fff;  
  47.             font-weight: bold;  
  48.             text-align: left;  
  49.         }  
  50.         .mydatagrid a /** FOR THE PAGING ICONS  **/  
  51.          {  
  52.             background-color: Transparent;  
  53.             padding: 5px 5px 5px 5px;  
  54.             color: #fff;  
  55.             text-decoration: none;  
  56.             font-weight: bold;  
  57.         }  
  58.         /*.mygrdContent a:hover /** FOR THE PAGING ICONS  HOVER STYLES**/  
  59.         {  
  60.             background-color: #000;  
  61.             color: #fff;  
  62.         }*/  
  63.         .mygrdContent span /** FOR THE PAGING ICONS CURRENT PAGE INDICATOR **/  
  64.          {  
  65.             background-color: #c9c9c9;  
  66.             color: #000;  
  67.             padding: 5px 5px 5px 5px;  
  68.         }  
  69.         .pager  
  70.         {  
  71.             background-color: #646464;  
  72.             font-family: Arial;  
  73.             color: White;  
  74.             height: 30px;  
  75.             text-align: left;  
  76.         }  
  77.         .mygrdContent td  
  78.         {  
  79.             padding: 5px;  
  80.         }  
  81.         .mygrdContent th  
  82.         {  
  83.             padding: 5px;  
  84.         }  
  85.         .inputbtn  
  86. {  
  87.     -moz-border-radius: 5px;  
  88.     border-radius: 5px;  
  89.     border: 1px solid gray;  
  90.     padding:0 3px 0 3px;  
  91.     display:inline-block;  
  92.     text-decoration:none;  
  93.     background:#595651;  
  94.     color:#FFFFFF;  
  95.     cursor:pointer;  
  96.     font:11px sans-serif;  
  97. }  
  98.      .bordereffect  
  99. {  
  100.     color: #1abc9c;  
  101.     background-color: Transparent;  
  102.     padding: 10px;  
  103.     border: solid 2px #1abc9c;  
  104.     font-size: 20px;  
  105.     font-weight: lighter;  
  106.     font-family: Consolas;  
  107.   
  108.     -moz-border-radius: 0px 0px 0px 0px;  
  109.     border-radius: 0px 0px 0px 0px;  
  110.            margin-top: 12px;  
  111.        }  
  112.   
  113.     </style>   
  114.   
  115.   
  116.     <title></title>  
  117.     <style type="text/css">  
  118.         .auto-style1 {  
  119.             width: 100%;  
  120.         }  
  121.         .input-lg {}  
  122.     </style>  
  123.     </head>  
  124. <body>  
  125.     <form id="form1" runat="server">  
  126.     <div>  
  127.     <br />  
  128.         Ref No.  
  129.          <asp:TextBox ID="txtRefno" CssClass="form-control input-lg"   Placeholder="Ref No"  runat="server" OnTextChanged="txtRefno_TextChanged" AutoPostBack="True"></asp:TextBox>  
  130.           Order No.  
  131.                  <asp:TextBox ID="txtOrder" CssClass="form-control input-lg"  Placeholder="Order No"  runat="server" Height="16px" Width="68px"></asp:TextBox>  
  132.   
  133.         <asp:Label ID="lbmsg" runat="server" Text="." Font-Bold="True" Font-Size="Large" ForeColor="Red"></asp:Label>  
  134.   
  135.           Pack No :  
  136.                  <asp:TextBox ID="txtpackno" CssClass="form-control input-lg"  Placeholder="Order No" AutoPostBack="true"  runat="server" Height="16px" Width="68px" OnTextChanged="txtpackno_TextChanged"></asp:TextBox>  
  137.   
  138.         <br/>  
  139.         <br />  
  140.   
  141.   
  142.   
  143.                        <asp:TextBox ID="TextBox1" AutoPostBack="true" runat="server"  Placeholder="Input Bale No"   OnTextChanged="TextBox1_TextChanged" Height="16px" Width="100px" style="margin-left: 0px"></asp:TextBox>  
  144.         <asp:DropDownList ID="DropDownList1" runat="server" Enabled="false" Height="20px" Width="130px">  
  145.         </asp:DropDownList>  
  146.       
  147.         <asp:TextBox ID="txtorderno" Placeholder="Order No"  readonly="true" runat="server" Height="16px" Width="51px"></asp:TextBox>  
  148.       
  149.         <asp:TextBox ID="txtqty" Placeholder="QTY"  readonly="true" runat="server" Height="16px" Width="56px"></asp:TextBox>  
  150.       
  151.        
  152.         <asp:Button ID="Button1" runat="server" Text="Add" OnClick="Button1_Click" Height="26px" Width="35px" />  
  153.       
  154.     </div>  
  155.         <table class="auto-style1">  
  156.             <tr>  
  157.                 <td> </td>  
  158.                 <td>  
  159.                     <asp:GridView ID="GridView1"  runat="server" HeaderStyle-BackColor="#66ccff" HeaderStyle-ForeColor="White"  
  160.     CssClass="mygrdContent" PagerStyle-CssClass="pager" HeaderStyle-CssClass="header" RowStyle-CssClass="rows" AutoGenerateColumns="false" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" AllowSorting="True" OnRowDataBound="GridView1_RowDataBound" >  
  161.     <Columns>  
  162.           <%--<asp:BoundField DataField="Prdno" ReadOnly="True" HeaderText="Bale_No" />--%>  
  163.          <asp:TemplateField HeaderText="Bale_No">  
  164.                                 <ItemTemplate>  
  165.                                     <asp:Label ID="Prdno" runat="server" Text='<%#Bind("Prdno")%>'></asp:Label>  
  166.                                 </ItemTemplate>  
  167.              </asp:TemplateField>  
  168.   
  169.   
  170.                <%--<asp:BoundField DataField="_PckID" HeaderText="PackID" Visible="false" />--%>  
  171.   
  172.            <asp:TemplateField HeaderText="Bale_No" Visible="false">  
  173.                                 <ItemTemplate>  
  174.                                     <asp:Label ID="_PID" runat="server" Text='<%#Bind("_PID")%>'></asp:Label>  
  175.                                 </ItemTemplate>  
  176.              </asp:TemplateField>  
  177.   
  178.         <%--<asp:BoundField DataField="Descriptionitem" HeaderText="Descriptionitem" ReadOnly="true" />--%>  
  179.   
  180.          <asp:TemplateField HeaderText="Description">  
  181.                                 <ItemTemplate>  
  182.                                     <asp:Label ID="Descriptionitem" runat="server" Text='<%#Bind("Descriptionitem")%>'></asp:Label>  
  183.                                 </ItemTemplate>  
  184.              </asp:TemplateField>  
  185.   
  186.           <%--<asp:BoundField DataField="Orderno" ControlStyle-Width="20px"  HeaderText="Orderno" >  
  187. <ControlStyle Width="20px"></ControlStyle>  
  188.           </asp:BoundField>--%>  
  189.   
  190.          <asp:TemplateField HeaderText="Orderno" >  
  191.                                 <ItemTemplate>  
  192.                                     <asp:Label ID="Orderno" runat="server" Text='<%#Bind("Orderno")%>'></asp:Label>  
  193.                                 </ItemTemplate>  
  194.              </asp:TemplateField>  
  195.   
  196.   
  197.   
  198.         <%--<asp:BoundField DataField="QTY" ControlStyle-Width="20px"  HeaderText="QTY" >  
  199.        
  200. <ControlStyle Width="20px"></ControlStyle>  
  201.           </asp:BoundField>--%>  
  202.   
  203.              <asp:TemplateField HeaderText="QTY" >  
  204.                                 <ItemTemplate>  
  205.                                     <asp:Label ID="QTY" runat="server" Text='<%#Bind("QTY")%>'></asp:Label>  
  206.                                 </ItemTemplate>  
  207.              </asp:TemplateField>  
  208.        
  209.         <asp:TemplateField>  
  210.             <ItemTemplate>  
  211.                 <%--<asp:LinkButton ID="lnkEdit" Text="Edit" runat="server" CommandName="Edit" />--%>  
  212.             </ItemTemplate>  
  213.             <EditItemTemplate>  
  214.               <%--  <asp:LinkButton ID="lnkUpdate" Text="Update" runat="server" OnClick="OnUpdate" />  
  215.                 <asp:LinkButton ID="lnkCancel" Text="Cancel" runat="server" OnClick="OnCancel" />--%>  
  216.             </EditItemTemplate>  
  217.         </asp:TemplateField>  
  218.         <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />  
  219.     </Columns>  
  220.   
  221. <HeaderStyle BackColor="#66CCFF" ForeColor="White"></HeaderStyle>  
  222.                         <SelectedRowStyle BackColor="Yellow" />  
  223. </asp:GridView>  
  224.                 </td>  
  225.                 <td> </td>  
  226.                 <td> </td>  
  227.             </tr>  
  228.             <tr>  
  229.                 <td> </td>  
  230.                 <td>  
  231.                     <asp:Button ID="Save" runat="server" Height="25px" Text="Save" Width="73px" BackColor="#66FFFF" CssClass="inputbtn" Font-Names="Aharoni" ForeColor="#000066" OnClick="Save_Click" />  
  232.                     <asp:Button ID="btn_Update" runat="server" Height="25px" Text="Update" Width="73px" BackColor="#66FFFF" CssClass="inputbtn" Font-Names="Aharoni" ForeColor="#000066" OnClick="btn_Update_Click" />  
  233.                 </td>  
  234.                 <td> </td>  
  235.                 <td> </td>  
  236.             </tr>  
  237.             <tr>  
  238.                 <td> </td>  
  239.                 <td> </td>  
  240.                 <td> </td>  
  241.                 <td> </td>  
  242.             </tr>  
  243.             <tr>  
  244.                 <td> </td>  
  245.                 <td> </td>  
  246.                 <td> </td>  
  247.                 <td> </td>  
  248.             </tr>  
  249.         </table>  
  250.     </form>  
  251. </body>  
  252. </html>  
here is my c# code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Configuration;  
  8. using System.Data;  
  9. using System.Data.SqlClient;  
  10.   
  11. namespace WebApplication1  
  12. {  
  13.     public partial class BalePack : System.Web.UI.Page  
  14.     {  
  15.         SqlConnection con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SPS;MultipleActiveResultSets=True;");  
  16.         // QryMgmt dm = new QryMgmt();  
  17.         DataTable dt = new DataTable();  
  18.         // DataRow dr;  
  19.         protected void Page_Load(object sender, EventArgs e)  
  20.         {  
  21.             if (!Page.IsPostBack)  
  22.             {  
  23.                 //this.BindGrid();  
  24.                 // txtpno.Text = String.Empty;  
  25.                 dt.Columns.Add("Prdno");  
  26.                 dt.Columns.Add("Descriptionitem");  
  27.                 dt.Columns.Add("Codeitem");  
  28.                 dt.Columns.Add("_PID");  
  29.                 dt.Columns.Add("orderno");  
  30.                 dt.Columns.Add("QTY");  
  31.                 ViewState["dt"] = dt;  
  32.                 itemload();  
  33.   
  34.             }  
  35.   
  36.   
  37.         }  
  38.   
  39.         private void itemload()  
  40.         {  
  41.             con.Open();  
  42.             SqlDataAdapter adpbp = new SqlDataAdapter("select * from ItemMasterFile ", con);  
  43.             DataSet dsbp = new DataSet();  
  44.             adpbp.Fill(dsbp);  
  45.             DropDownList1.DataSource = dsbp.Tables[0];  
  46.             DropDownList1.DataTextField = "Descriptionitem";  
  47.             DropDownList1.DataValueField = "Codeitem";  
  48.             DropDownList1.DataBind();  
  49.             DropDownList1.Items.Insert(0, new ListItem("Select Item Name"""));  
  50.   
  51.             con.Close();  
  52.         }  
  53.   
  54.         protected void TextBox1_TextChanged(object sender, EventArgs e)  
  55.         {  
  56.             String strQuery = "select Codeitem,Orderno,Prdqty From Probale where" +  
  57.                                              " Prdno = @Prdno";  
  58.             // SqlConnection con = new SqlConnection();  
  59.             SqlCommand cmde = new SqlCommand();  
  60.             cmde.Parameters.AddWithValue("@Prdno", TextBox1.Text);  
  61.             cmde.CommandType = CommandType.Text;  
  62.             cmde.CommandText = strQuery;  
  63.             cmde.Connection = con;  
  64.             try  
  65.             {  
  66.                 con.Open();  
  67.                 SqlDataReader sdr = cmde.ExecuteReader();  
  68.                 while (sdr.Read())  
  69.                 {  
  70.                     //DropDownList1.SelectedValue = sdr[0].ToString();  
  71.                     DropDownList1.SelectedValue = sdr["Codeitem"].ToString();  
  72.   
  73.                     txtorderno.Text = sdr["Orderno"].ToString();  
  74.                     txtqty.Text = sdr["Prdqty"].ToString();  
  75.                     lbmsg.Text = "";  
  76.   
  77.                 }  
  78.             }  
  79.             catch (Exception ex)  
  80.             {  
  81.                 throw ex;  
  82.             }  
  83.         }  
  84.   
  85.         protected void Button1_Click(object sender, EventArgs e)  
  86.         {  
  87.   
  88.   
  89.             if  
  90.                  (txtOrder.Text == "")  
  91.             {  
  92.                 Response.Write("<script language='javascript'>alert('Please Input Orderno');</script>");  
  93.             }  
  94.             else  
  95.             {  
  96.                 if  
  97.                      (txtorderno.Text == "")  
  98.                 {  
  99.                     Response.Write("<script language='javascript'>alert('Please Input Bale No');</script>");  
  100.                 }  
  101.                 else if  
  102.                 (txtqty.Text == "")  
  103.                 {  
  104.                     Response.Write("<script language='javascript'>alert('Please Input QTY');</script>");  
  105.                 }  
  106.                 else if  
  107.   
  108.                     ((int.Parse(txtOrder.Text) != (int.Parse(txtorderno.Text))))  
  109.                     lbmsg.Text = "Bale is Not in order";  
  110.                 else if  
  111.                         (txtorderno.Text == "")  
  112.                 {  
  113.                     Response.Write("<script language='javascript'>alert('Please Input Orderno');</script>");  
  114.                 }  
  115.   
  116.                 else if (DropDownList1.SelectedValue == "")  
  117.                 {  
  118.                     Response.Write("<script language='javascript'>alert('Please Input Item');</script>");  
  119.                 }  
  120.                 else  
  121.                 {  
  122.                     {  
  123.                         if (DropDownList1.SelectedItem != null)  
  124.                         {  
  125.                             // get value and text which item you have selected  
  126.                             int codeitem = Convert.ToInt32(DropDownList1.SelectedItem.Value.ToString());  
  127.                             string Descriptionitem = DropDownList1.SelectedItem.Text.ToString();  
  128.   
  129.                             //delete the selected item from dropdownlist  
  130.                             //DataTable dtdrop = ViewState["dropdownlistdata"] as DataTable;  
  131.                             //for (int i = dtdrop.Rows.Count - 1; i >= 0; i--)  
  132.                             //{  
  133.                             //    DataRow dr1 = dtdrop.Rows[i];  
  134.                             //    if (dr1["Codeitem"].ToString() == codeitem.ToString())  
  135.                             //        dr1.Delete();  
  136.                             //}  
  137.                             //  dtdrop.AcceptChanges();  
  138.                             //ViewState["dropdownlistdata"] = dtdrop;  
  139.                             //DropDownList1.DataSource = dtdrop;  
  140.                             //DropDownList1.DataBind();  
  141.   
  142.   
  143.   
  144.   
  145.                             //add the selected item to gridview  
  146.   
  147.                             DataTable dtgridview = ViewState["dt"as DataTable;  
  148.                             DataRow dr2 = dtgridview.NewRow();  
  149.                             dr2["Prdno"] = TextBox1.Text;  
  150.                             dr2["Codeitem"] = codeitem;  
  151.                             dr2["Descriptionitem"] = Descriptionitem;  
  152.                             dr2["Orderno"] = txtorderno.Text;  
  153.   
  154.                             dr2["QTY"] = txtqty.Text;  
  155.                             dtgridview.Rows.Add(dr2);  
  156.                             ViewState["dt"] = dtgridview;  
  157.                             GridView1.DataSource = dtgridview;  
  158.                             GridView1.DataBind();  
  159.   
  160.                             clear();  
  161.                         }  
  162.                     }  
  163.                 }  
  164.             }  
  165.         }  
  166.   
  167.         private void clear()  
  168.         {  
  169.             TextBox1.Text = "";  
  170.             txtqty.Text = "";  
  171.             txtorderno.Text = "";  
  172.             DropDownList1.SelectedValue = "";  
  173.   
  174.   
  175.         }  
  176.   
  177.         protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)  
  178.         {  
  179.             //        if (e.Row.RowType == DataControlRowType.DataRow)  
  180.             //        {  
  181.             //            string CodeItem = e.Row.Cells[0].Text;  
  182.             //            foreach (Button button in e.Row.Cells[3].Controls.OfType<Button>())  
  183.             //            {  
  184.             //                if (button.CommandName == "Delete")  
  185.             //                {  
  186.             //                    button.Attributes["onclick"] = "if(!confirm('Do you want to delete " + CodeItem + "?')){ return false; };";  
  187.             //                }  
  188.             //            }  
  189.             //        }  
  190.             //    }  
  191.             //}  
  192.         }  
  193.   
  194.         protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)  
  195.         {  
  196.             int index = Convert.ToInt32(e.RowIndex);  
  197.             DataTable dt = (DataTable)ViewState["dt"];  
  198.             dt.Rows[index].Delete();  
  199.             ViewState["dt"] = dt;  
  200.             GridView1.DataSource = dt;  
  201.             GridView1.DataBind();  
  202.         }  
  203.   
  204.         protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)  
  205.         {  
  206.             GridView1.EditIndex = e.NewEditIndex;  
  207.             BindGrid();  
  208.         }  
  209.   
  210.         private void BindGrid()  
  211.         {  
  212.             GridView1.DataSource = ViewState["dt"as DataTable;  
  213.             GridView1.DataBind();  
  214.         }  
  215.   
  216.         protected void txtRefno_TextChanged(object sender, EventArgs e)  
  217.         {  
  218.             String strQuery = "select Orderno From SalesOrder where" +  
  219.                                             " Order_Ref_No = @Order_Ref_No";  
  220.             // SqlConnection con = new SqlConnection();  
  221.             SqlCommand cmde = new SqlCommand();  
  222.             cmde.Parameters.AddWithValue("@Order_Ref_No", txtRefno.Text);  
  223.             cmde.CommandType = CommandType.Text;  
  224.             cmde.CommandText = strQuery;  
  225.             cmde.Connection = con;  
  226.             try  
  227.             {  
  228.                 con.Open();  
  229.                 SqlDataReader sdr = cmde.ExecuteReader();  
  230.                 while (sdr.Read())  
  231.                 {  
  232.   
  233.   
  234.                     txtOrder.Text = sdr["Orderno"].ToString();  
  235.   
  236.   
  237.                 }  
  238.             }  
  239.             catch (Exception ex)  
  240.             {  
  241.                 throw ex;  
  242.             }  
  243.         }  
  244.   
  245.         protected void Save_Click(object sender, EventArgs e)  
  246.         {  
  247.   
  248.             using (SqlCommand cmd = new SqlCommand("[Sp_BalPakinsert]", con))  
  249.             {  
  250.                 cmd.CommandType = CommandType.StoredProcedure;  
  251.   
  252.                 cmd.Parameters.AddWithValue("@Order_Ref_No", txtRefno.Text);  
  253.   
  254.                 cmd.Parameters.AddWithValue("@OrderNo", txtOrder.Text);  
  255.   
  256.                 con.Open();  
  257.                 _PID = Convert.ToInt32(cmd.ExecuteScalar());  
  258.                 con.Close();  
  259.   
  260.                 DataTable dt = (DataTable)ViewState["dt"];  
  261.                 int codeitem, qty, orderno, prdno;  
  262.   
  263.                 foreach (DataRow row in dt.Rows)  
  264.                 {  
  265.   
  266.                     //pid = int.Parse(row["_PID"].ToString());  
  267.                     prdno = int.Parse(row["Prdno"].ToString());  
  268.                     orderno = int.Parse(row["Orderno"].ToString());  
  269.                     qty = int.Parse(row["QTY"].ToString());  
  270.                     codeitem = int.Parse(row["Codeitem"].ToString());  
  271.   
  272.                     this.InsertRows(codeitem, qty, orderno, prdno);  
  273.                 }  
  274.             }  
  275.         }  
  276.   
  277.         private void InsertRows(int codeitem, int qty, int orderno, int prdno)  
  278.         {  
  279.             con.Open();  
  280.             using (SqlCommand cmd = new SqlCommand("[SP_BalPakDetail_Insert]", con))  
  281.             {  
  282.   
  283.                 cmd.CommandType = CommandType.StoredProcedure;  
  284.                  
  285.                // cmd.Parameters.AddWithValue("@PDID", _PID);  
  286.                 cmd.Parameters.AddWithValue("@PID", _PID);  
  287.                 cmd.Parameters.AddWithValue("@CodeItem", codeitem);  
  288.                 cmd.Parameters.AddWithValue("@QTY", qty);  
  289.                 cmd.Parameters.AddWithValue("@Orderno", orderno);  
  290.                 cmd.Parameters.AddWithValue("@Prdno", prdno);  
  291.   
  292.                 cmd.ExecuteNonQuery();  
  293.                 con.Close();  
  294.             }  
  295.         }  
  296.   
  297.   
  298.         public int _PID { getset; }  
  299.   
  300.   
  301.         // Search By Pack No of Bale //  
  302.   
  303.         protected void txtpackno_TextChanged(object sender, EventArgs e)  
  304.         {  
  305.             String strQuery = "select Orderno,Order_Ref_No From tbl_BalPacM where" +  
  306.                                             " PID = @PID";  
  307.             // SqlConnection con = new SqlConnection();  
  308.             SqlCommand cmde = new SqlCommand();  
  309.             cmde.Parameters.AddWithValue("@PID", txtpackno.Text);  
  310.             cmde.CommandType = CommandType.Text;  
  311.             cmde.CommandText = strQuery;  
  312.             cmde.Connection = con;  
  313.             try  
  314.             {  
  315.                 con.Open();  
  316.                 SqlDataReader sdr = cmde.ExecuteReader();  
  317.                 while (sdr.Read())  
  318.                 {  
  319.   
  320.   
  321.                     txtOrder.Text = sdr["Orderno"].ToString();  
  322.                     txtRefno.Text = sdr["Order_Ref_No"].ToString();  
  323.   
  324.                 }  
  325.             }  
  326.             catch (Exception ex)  
  327.             {  
  328.                 throw ex;  
  329.             }  
  330.             SqlCommand cmdbno = new SqlCommand("[SP_PackViewbyID]", con);  
  331.   
  332.             cmdbno.CommandType = CommandType.StoredProcedure;  
  333.             cmdbno.Parameters.AddWithValue("PID", txtpackno.Text);  
  334.             SqlDataAdapter adptbno = new SqlDataAdapter(cmdbno);  
  335.             DataTable dtbno = new DataTable();  
  336.             adptbno.Fill(dtbno);  
  337.             GridView1.DataSource = dtbno;  
  338.             GridView1.DataBind();  
  339.             cmdbno.Dispose();  
  340.             con.Close();  
  341.         }  
  342.   
  343.         protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
  344.         {  
  345.             if (e.Row.RowType == DataControlRowType.DataRow)  
  346.             {  
  347.                 Label lbl = (Label)e.Row.FindControl("Prdno");  
  348.             }  
  349.         }  
  350.   
  351.         protected void btn_Update_Click(object sender, EventArgs e)  
  352.         {  
  353.   
  354.         }  
  355.     }  
  356. }  
  357.   
  358.         
PLeasae Guide 

Answers (3)