嵌套的gridview错误 [英] nested gridview error

查看:67
本文介绍了嵌套的gridview错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

geting error输入字符串的格式不正确。



编译时



错误显示在这一行

int task_id = Convert.ToInt32(e.Row.Cells [1] .Text);









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);




<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();

}

}

SqlConnect ion 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();

}

}









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();
}
}

推荐答案

您好,



请在转换时查看,数据是你进入e.Row.Cells [1] .Text。如果它是纯文本而不是像Convert.ToInt32(abc)那样的数字。 e.Row.Cells [1] .Text应该是一个数字,然后才会转换为int taskId。



问候,

Praneet Nadkar
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


这篇关于嵌套的gridview错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆