none
Input string was not in a correct format. Please help

    Question

  • protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            this.GridView1.Attributes["style"] = @"opacity:0.4;
                                                   filter:alpha(opacity=40);";
    ////Exception Here
           int index = Convert.ToInt32(e.CommandArgument); 
    //////////////////////////////////////////////// I donot why CommandArgument is empty
            if (e.CommandName.ToLower() == "add")
            {
                
                Report.Text=GridView1.Rows[index].Cells[2].Text;
                add_panel.Visible = true;
            }
        }

    Shival Thakur
    Monday, September 26, 2011 6:51 AM

Answers


  • CommandArgument is an optional parameter passed to the Command event along with the associated CommandName. The default value is String.Empty.

    As you did not set it any where you are getting empty string.

    So you should set it as.

    <asp:Button Text="Add" runat="server" ID="add" CommandName="ADD" CommandArgument="arguments" CssClass="button"  CausesValidation="false"  />


    • Marked as answer by SP Thakur Monday, September 26, 2011 7:14 AM
    Monday, September 26, 2011 7:10 AM

All replies

  • How you declare this gridview.

    Paste the code you are using to declare this.

     

    I suspect you are not setting CommandName property.



    • Edited by Zain_Ali Monday, September 26, 2011 7:05 AM
    Monday, September 26, 2011 7:02 AM
  • You can check with

    int index = Convert.ToInt32(e.CommandArgument.ToString()); 
    

     


    Hasibul Haque,MCC,MCPD blog.e-rains.com
    Monday, September 26, 2011 7:03 AM
  •  <asp:GridView ID="GridView1" runat="server" Width="750px" 
                AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand">
            <Columns> 
            <asp:TemplateField HeaderText="Add ID">
            <ItemTemplate>
            <asp:Button Text="Add" runat="server" ID="add" CommandName="ADD" CssClass="button"  CausesValidation="false"  />
               
          
            </ItemTemplate>
            </asp:TemplateField>
            
             <asp:TemplateField HeaderText="Remove ID">
            <ItemTemplate>
            <asp:Button Text="Remove" runat="server" ID="remove" CommandName="remove" CssClass="button" CausesValidation="false" />
            
            </ItemTemplate>
            </asp:TemplateField>
            
           
            <asp:BoundField HeaderText="Report"  DataField="Report_Type" ReadOnly="true"/>
          
            <asp:TemplateField HeaderText="Email To">
            <ItemTemplate>
            <%# Eval("Email_To") %>
            </ItemTemplate>
                  
            </asp:TemplateField>
            <asp:BoundField DataField="CC" HeaderText="CC" />
            <asp:BoundField DataField="BCC"  HeaderText="BCC" />
            </Columns>
            <RowStyle CssClass="gvrow" />
            <AlternatingRowStyle CssClass="gridalterrow" />
            <HeaderStyle CssClass="gridheader"/>
            </asp:GridView>
    Code Behind
     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                add_panel.Visible = false;
                connection = new SqlConnection(constr);
                connection.Open();
                adapter = new SqlDataAdapter("select * from Email_Id_Table", connection);
                set = new DataSet();
                adapter.Fill(set);
                connection.Close();
                connection.Dispose();
                GridView1.DataSource = set.Tables[0];
                GridView1.DataBind();
                set.Dispose();
            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            this.GridView1.Attributes["style"] = @"opacity:0.4;
                                                   filter:alpha(opacity=40);";
          
            if (e.CommandName.ToLower() == "add")
            {
             
                int index = Convert.ToInt32(e.CommandArgument); 
                Report.Text=GridView1.Rows[index].Cells[2].Text;
                add_panel.Visible = true;
            }
        }

    Shival Thakur
    • Edited by SP Thakur Monday, September 26, 2011 7:06 AM
    Monday, September 26, 2011 7:05 AM

  • CommandArgument is an optional parameter passed to the Command event along with the associated CommandName. The default value is String.Empty.

    As you did not set it any where you are getting empty string.

    So you should set it as.

    <asp:Button Text="Add" runat="server" ID="add" CommandName="ADD" CommandArgument="arguments" CssClass="button"  CausesValidation="false"  />


    • Marked as answer by SP Thakur Monday, September 26, 2011 7:14 AM
    Monday, September 26, 2011 7:10 AM
  • Thanks......Working Now!!!!
    Shival Thakur
    Monday, September 26, 2011 7:15 AM