Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
geting error Input string was not in a correct format.

at the time of compile

error show here in this line
int task_id = Convert.ToInt32(e.Row.Cells[1].Text);




XML
<asp:GridView ID="post" runat="server" AutoGenerateColumns="false" DataKeyNames="task_id"
    OnRowDataBound="post_RowDataBound" GridLines="None" BorderStyle="Solid" BorderWidth="1px"  BorderColor="#df5015">
    <Columns>
        <asp:BoundField ItemStyle-Width="150px" DataField="task_id" HeaderText="id"  />
        <asp:BoundField ItemStyle-Width="150px" DataField="message" HeaderText="message" />
        <asp:BoundField ItemStyle-Width="150px" DataField="post_name" HeaderText="post name" />
        <asp:BoundField ItemStyle-Width="150px" DataField="curnt_date" HeaderText="date"  />
        <asp:BoundField ItemStyle-Width="150px" DataField="asign_name" HeaderText="asign name" />

        <asp:TemplateField>
            <ItemTemplate>
                <div id='div<%# Eval("task_id") %>' style="display: none; position: relative; left: 15px; overflow: auto">
                <asp:GridView ID="comment" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField ItemStyle-Width="150px" DataField="comment"  />
                         <asp:BoundField ItemStyle-Width="150px" DataField="rply_name"  />
                         <asp:BoundField ItemStyle-Width="150px" DataField="rpl_date"  />

                    </Columns>
                </asp:GridView>
            </ItemTemplate>

        </asp:TemplateField>


    </Columns>

</asp:GridView>
</div>








protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bindgridview();
}
}
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
protected void Bindgridview()
{
con.Open();
SqlCommand cmd = new SqlCommand("select task_id,message,post_name,curnt_date,asign_name from task", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
post.DataSource = ds;
post.DataBind();
}

protected void post_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
con.Open();
GridView gv = (GridView)e.Row.FindControl("comment");
int task_id = Convert.ToInt32(e.Row.Cells[1].Text);
SqlCommand cmd = new SqlCommand("select * from rply where task_id= " + task_id, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
gv.DataSource = ds;
gv.DataBind();
}
}
Posted

1 solution

Hi,

Please check at the time of conversion, what data are you getting in e.Row.Cells[1].Text. If it is a plain text and not a number like, Convert.ToInt32("abc"). The e.Row.Cells[1].Text should be a number, only then it will would cast to int taskId.

Regards,
Praneet Nadkar
 
Share this answer
 
Comments
Aarti Yadav 17-Oct-14 5:57am    
getting a number that is not a text so what to do know.. Not getting
[no name] 17-Oct-14 6:20am    
What is the value in e.Row.Cells[1].Text ?

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