Submit button error inside gridview

Last Reply on Aug 29, 2012 09:35 AM By RkHirpara

Posted on Aug 29, 2012 07:51 AM

hi all i added a button in the grid view so that when user click on that button,all of the data were go the database.

the grid code is

 

here is 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NewCampaign.aspx.cs" Inherits="NoticeBoard.WebForm1" %> 
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  <html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server">     <title></title> 
    <style type="text/css">         .style1         { 
            width: 160px;         }         .style2         { 
            width: 176px;         }         .style3         { 
            width: 160px;             height: 23px;         }         .style4 
        {             width: 176px;             height: 23px;         } 
        .style5         {             height: 23px;         } 
    </style>     </head>              
<body style="height: 551px; width: 797px" bgcolor="White">       
    <form id="form1" runat="server">     <div>         <br /> 
        <asp:GridView ID="noticeDetails" runat="server" AutoGenerateEditButton="True" 
            onrowediting="noticeDetails_RowEditing1" 
            onrowupdated="noticeDetails_RowUpdated1" 
            onrowupdating="noticeDetails_RowUpdating1"> 
        </asp:GridView>         <br />         <br /> 
        <asp:GridView ID="GridView1" runat="server"> 
        </asp:GridView>         <br /> 
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Submit" /> 
    </div>       <div>          <table style="width:100%;" 
     runat ="server" id="myform">             <tr> 
                <td class="style1">         
                   <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" 
                Text="Campaign ID Range" oncheckedchanged="RadioButton1_CheckedChanged" /> 
                  </td>                 <td class="style2"> 
                    <asp:TextBox ID="Txtadd5" runat="server"></asp:TextBox> 
                    <asp:Label ID="Label5" runat="server" Text="to"></asp:Label> 
                                               </td> 
                <td> 
                    <asp:TextBox ID="Txtadd6" runat="server"></asp:TextBox> 
                </td>             </tr>             <tr> 
                <td class="style1">                          
                      
                 <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="true" Text="Manual Entry" 
                oncheckedchanged="RadioButton2_CheckedChanged" />       
                                         </td> 
                <td class="style2"> 
                    <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    &nbsp;</td> 
                <td class="style2"> 
                    &nbsp;</td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label1" runat="server" Text="Promo Start Date"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd1" runat="server" ></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label2" runat="server" Text="Promo End Date"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd2" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style3"> 
                    <asp:Label ID="Label3" runat="server" Text="Execution Date"></asp:Label> 
                </td>                 <td class="style4"> 
                    <asp:TextBox ID="txtadd3" runat="server"></asp:TextBox> 
                </td>                 <td class="style5"> 
                </td>             </tr>             <tr> 
                <td class="style1"> 
                    <asp:Label ID="Label4" runat="server" Text="Expiry Date"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd4" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label6" runat="server" Text="CampaignName"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtaddee" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label7" runat="server" Text="PromoType"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtaddff" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label8" runat="server" Text="Service"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd7" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label9" runat="server" Text="MinimumThreshold"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd8" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label10" runat="server" Text="BonusMin"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd9" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label11" runat="server" Text="BonusSms"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd10" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label12" runat="server" Text="BonusGprs"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd11" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label13" runat="server" Text="SmsDeliveryFlag"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd12" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    <asp:Label ID="Label14" runat="server" Text="VlrDeliveryFlag"></asp:Label> 
                </td>                 <td class="style2"> 
                    <asp:TextBox ID="txtadd13" runat="server"></asp:TextBox> 
                </td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    &nbsp;</td> 
                <td class="style2"> 
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click1" 
                        Text="Submit" />                 </td> 
                <td>                     &nbsp;</td> 
            </tr>             <tr> 
                <td class="style1"> 
                    &nbsp;</td> 
                <td class="style2"> 
                    &nbsp;</td>                 <td> 
                    &nbsp;</td>             </tr> 
            <tr>                 <td class="style1"> 
                    &nbsp;</td> 
                <td class="style2"> 
                    &nbsp;</td>                 <td> 
                    &nbsp;</td>             </tr> 
        </table>         </div> 
        <div runat="server" id="editabletable">         </div> 
        <p>     </p>     </form> </body>
 
in .cs
 

 

using System; using System.Configuration; using System.Collections.Generic; 
using System.Linq; using System.Web; using System.Web.UI; 
using System.Web.UI.WebControls; using System.Data.Odbc; using System.Data; 
using System.Drawing; using System.Collections; using System.Web.Security;   
using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; 
using NoticeBoard.BusinessLogic; namespace NoticeBoard { 
    public partial class WebForm1 : System.Web.UI.Page     { 
        DataTable dt;  
        protected void Page_Load(object sender, EventArgs e)         {   
            dt = new DataTable("tblTest"); 
            DataColumn dc1 = new DataColumn(); 
            dc1.DataType = typeof(String); 
            dc1.ColumnName = "PromoStartDate"; 
            DataColumn dc2 = new DataColumn(); 
            dc2.DataType = typeof(String); 
            dc2.ColumnName = "PromoEndDate"; 
            DataColumn dc3 = new DataColumn(); 
            dc3.DataType = typeof(String); 
            dc3.ColumnName = "ExecutionDate"; 
            DataColumn dc4 = new DataColumn(); 
            dc4.DataType = typeof(String); 
            dc4.ColumnName = "ExpiryDate"; 
            DataColumn dc5 = new DataColumn(); 
            dc5.DataType = typeof(String); 
            dc5.ColumnName = "CampaignIDRange"; 
            DataColumn dc6 = new DataColumn(); 
            dc6.DataType = typeof(String); 
            dc6.ColumnName = "CampaignName"; 
            DataColumn dc7 = new DataColumn(); 
            dc7.DataType = typeof(String); 
            dc7.ColumnName = "PromoType"; 
            DataColumn dc8 = new DataColumn(); 
            dc8.DataType = typeof(String); 
            dc8.ColumnName = "Service"; 
            DataColumn dc9 = new DataColumn(); 
            dc9.DataType = typeof(String); 
            dc9.ColumnName = "MinimumThreshold"; 
            DataColumn dc10 = new DataColumn(); 
            dc10.DataType = typeof(String); 
            dc10.ColumnName = "BonusMin"; 
            DataColumn dc11 = new DataColumn(); 
            dc11.DataType = typeof(String); 
            dc11.ColumnName = "BonusSms"; 
            DataColumn dc12 = new DataColumn(); 
            dc12.DataType = typeof(String); 
            dc12.ColumnName = "BonusGprs"; 
            DataColumn dc13 = new DataColumn(); 
            dc13.DataType = typeof(String); 
            dc13.ColumnName = "SmsDeliveryFlag"; 
            DataColumn dc14 = new DataColumn(); 
            dc14.DataType = typeof(String); 
            dc14.ColumnName = "VlrDeliveryFlag";     
            dt.Columns.Add(dc1);             dt.Columns.Add(dc2); 
            dt.Columns.Add(dc3);             dt.Columns.Add(dc4); 
            dt.Columns.Add(dc5);             dt.Columns.Add(dc6); 
            dt.Columns.Add(dc7);             dt.Columns.Add(dc8); 
            dt.Columns.Add(dc9);             dt.Columns.Add(dc10); 
            dt.Columns.Add(dc11);             dt.Columns.Add(dc12); 
            dt.Columns.Add(dc13);             dt.Columns.Add(dc14);            
        protected void TextBox3_TextChanged(object sender, EventArgs e) 
        {          }  
        protected void TextBox1_TextChanged(object sender, EventArgs e) 
        {          } 
        protected void RadioButton1_CheckedChanged(object sender, EventArgs e) 
        {             if (RadioButton1.Checked == true)             { 
                RadioButton2.Enabled = false;             }             else 
            {                 RadioButton2.Enabled = true;             } 
        }  
        protected void RadioButton2_CheckedChanged(object sender, EventArgs e) 
        {             if (RadioButton2.Checked == true)             { 
                RadioButton1.Enabled = false;             }             else 
            {                 RadioButton1.Enabled = true;             } 
        }            protected void Button1_Click1(object sender, EventArgs e) 
        {                         { 
                Session["PromoStartDate"] += txtadd1.Text + "|"; 
                Session["PromoEndDate"] += txtadd2.Text + "|"; 
                Session["ExecutionDate"] += txtadd3.Text + "|"; 
                Session["ExpiryDate"] += txtadd4.Text + "|"; 
                Session["CampaignName"] += txtaddee.Text + "|"; 
                Session["PromoType"] += txtaddff.Text + "|"; 
                Session["Service"] += txtadd7.Text + "|"; 
                Session["MinimumThreshold"] += txtadd8.Text + "|"; 
                Session["BonusMin"] += txtadd9.Text + "|"; 
                Session["BonusSms"] += txtadd10.Text + "|"; 
                Session["BonusGprs"] += txtadd11.Text + "|"; 
                Session["SmsDeliveryFlag"] += txtadd12.Text + "|"; 
                Session["VlrDeliveryFlag"] += txtadd13.Text + "|"; 
                if (RadioButton1.Checked)                 { 
                    Session["CampaignIDRange"] += Txtadd5.Text + "|"; 
                    Session["CampaignIDRange2"] += Txtadd6.Text + "|"; 
                }                 else                 { 
                    Session["CampaignIDRange"] += TextBox7.Text + "|"; 
                    Session["CampaignIDRange2"] += TextBox7.Text + "|"; 
                }                 CreateTable();             }          } 
        public void CreateTable()         {  
            string[] sa = Session["PromoStartDate"].ToString().Split('|'); 
            string[] sb = Session["PromoEndDate"].ToString().Split('|'); 
            string[] sc = Session["ExecutionDate"].ToString().Split('|'); 
            string[] sd = Session["ExpiryDate"].ToString().Split('|'); 
            string[] se = Session["CampaignIDRange"].ToString().Split('|'); 
            string[] sf = Session["CampaignIDRange2"].ToString().Split('|'); 
            string[] sg = Session["CampaignName"].ToString().Split('|'); 
            string[] sh = Session["PromoType"].ToString().Split('|'); 
            string[] si = Session["Service"].ToString().Split('|'); 
            string[] sj = Session["MinimumThreshold"].ToString().Split('|'); 
            string[] sk = Session["BonusMin"].ToString().Split('|'); 
            string[] sl = Session["BonusSms"].ToString().Split('|'); 
            string[] sm = Session["BonusGprs"].ToString().Split('|'); 
            string[] sn = Session["SmsDeliveryFlag"].ToString().Split('|'); 
            string[] so = Session["VlrDeliveryFlag"].ToString().Split('|'); 
            int recordnum = sa.Length; 
            for (int j = 0; j < recordnum - 1; j++)             { 
                DataRow dr; 
                //innerhtml = innerhtml + "<tr>";   
                for (int k = Convert.ToInt32(se[j]); k <= Convert.ToInt32(sf[j]); k++) 
                {                     dr = dt.NewRow(); 
                    dr["PromoStartDate"] = sa[j].ToString(); 
                    dr["PromoEndDate"] = sb[j].ToString(); 
                    dr["ExecutionDate"] = sc[j].ToString(); 
                    dr["ExpiryDate"] = sd[j].ToString(); 
                    dr["CampaignIDRange"] = k.ToString(); 
                    dr["CampaignName"] = sg[j].ToString(); 
                    dr["PromoType"] = ""; 
                    dr["Service"] = ""; 
                    dr["MinimumThreshold"] = ""; 
                    dr["BonusMin"] = ""; 
                    dr["BonusSms"] = ""; 
                    dr["BonusGprs"] = ""; 
                    dr["SmsDeliveryFlag"] = ""; 
                    dr["VlrDeliveryFlag"] = "";  
                    //dr["CampaignIDRange"] = sf[j].ToString();  
                    dt.Rows.Add(dr);                  } 
                noticeDetails.DataSource = dt.DefaultView; 
                noticeDetails.DataBind(); 
                saveCode objj = new saveCode();                 objj.load(dt); 
            }         }           
        protected void noticeDetails_RowUpdated1(object sender, GridViewUpdatedEventArgs e) 
        {          }  
        protected void noticeDetails_RowEditing1(object sender, GridViewEditEventArgs e) 
        {          }  
        protected void Button2_Click(object sender, EventArgs e)         { 
            connection obj = new connection(); 
            string strquery = "";             DataTable dtt = new DataTable(); 
            saveCode o = new saveCode();             dtt = o.gettable();  
            for(int i = 0;i<dtt.Rows.Count;i++)             { 
                strquery = "Insert into dp_tmp.posting_values_stg(CAMPAIGN_NM,CAMPAIGN_ID,PROMO_TYPE,SERVICE_TYPE,PROMO_START_DT,PROMO_END_DT,PROMO_EXE_DT,MINIMUM_THRESHOLD,BONUS_MIN,BONUS_SMS,BONUS_GPRS,BONUS_BAL,EXPIRY_DATE,SMS_DELIVERY_STATUS,VLR_FLAG) VALUES('" +  
                    // first dynamic row but first column    dtt.Rows[i][0]  
                   dtt.Rows[i][2] + "','" + dtt.Rows[i][3] + "','" +dtt.Rows[i][4]+ "','" + dtt.Rows[i][5] + "','" + 
               dtt.Rows[i][6] + "','" + dtt.Rows[i][7] + "','" + dtt.Rows[i][8] + "','" + dtt.Rows[i][9] + "','" + dtt.Rows[i][10] + "','" + dtt.Rows[i][11] + "','" + dtt.Rows[i][12] + "','" + dtt.Rows[i][13] + "','" + dtt.Rows[i][14] + "','" + 
              dtt.Rows[i][15] + "','" + dtt.Rows[i][16] + "')"; 
            con.ExecuteQuery(strquery);             }         }     } }
 

but it gives error

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'ASP.form1_aspx' does not contain a definition for 'Button2_Click' and no extension method 'Button2_Click' accepting a first argument of type 'ASP.newcampaign_aspx' could be found (are you missing a using directive or an assembly reference?)
Source Error:

 
Line 49:         </asp:GridView>
Line 50:         <br />
Line 51: <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Submit" /> Line 52:     </div> 
Line 53:  

 

 

any body help me to remove this error

thank you

 

Posted on Aug 29, 2012 09:14 AM

Everything looks fine in code. try changing the event


Posted on Aug 29, 2012 09:35 AM

Hi there there, the page load is not being closed at all.., "}" should be there at the end of the every event look at the line no. 59 in the code you have paste.., once doing this you had better to Rebuild the solution or just simply build it.

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html