输入字符串的格式不正确,不知道错哪了 各位仁兄帮忙看看

lihui123 2009-07-28 10:52:08
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow GvRow = WageAccount_gv.Rows[index];
float c_wage = Convert.ToSingle(GvRow.Cells[3].FindControl("C_WAGE").ToString());输入字符串的格式不正确
float c_absence_count = Convert.ToSingle(GvRow.Cells[4].FindControl("c_absence_count").ToString());
float C_ALLOWANCE_ERRAND = Convert.ToSingle(GvRow.Cells[5].FindControl("C_ALLOWANCE_ERRAND").ToString());
float c_bonus1 = Convert.ToSingle(GvRow.Cells[6].FindControl("c_bonus1").ToString());
float c_bonus2 = Convert.ToSingle(GvRow.Cells[7].FindControl("c_bonus2").ToString());
float c_bonus3 = Convert.ToSingle(GvRow.Cells[8].FindControl("c_bonus3").ToString());
float c_deduct = Convert.ToSingle(GvRow.Cells[9].FindControl("c_deduct").ToString());
float c_insure = Convert.ToSingle(GvRow.Cells[10].FindControl("c_insure").ToString());
...全文
709 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Adechen 2009-07-28
  • 打赏
  • 举报
回复
GvRow.Cells[3].FindControl("C_WAGE").ToString()
返回一个conftrol
阿彪兄 2009-07-28
  • 打赏
  • 举报
回复
楼上正解 ,不能将Control类型转换为 float类型
Aderlee 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lihui123 的回复:]
幕白兄


C_WAGE 是Gridview里的一个TemplateFiled
[/Quote]
那你就用个控件,如Label之类的先包住它再去FindControl啦,很明显GvRow.Cells[3].FindControl("C_WAGE").ToString()返回的是空值。
lihui123 2009-07-28
  • 打赏
  • 举报
回复
幕白兄


C_WAGE 是Gridview里的一个TemplateFiled
cpp2017 2009-07-28
  • 打赏
  • 举报
回复
FindControl("C_WAGE").ToString()返回的是这个Control的类型.

你要确定这个是什么控件

假设是TextBox

应该是

Convert.ToSingle((TextBox)GvRow.Cells[3].FindControl("C_WAGE")).Text)

其他的类似.
YL_Show 2009-07-28
  • 打赏
  • 举报
回复
学习
lihui123 2009-07-28
  • 打赏
  • 举报
回复
幕白 ……太感谢你们了
cpp2017 2009-07-28
  • 打赏
  • 举报
回复
Convert.ToSingle(((Label)GvRow.Cells[3].FindControl("C_WAGE")
).Text)
lihui123 2009-07-28
  • 打赏
  • 举报
回复
幕白兄 这里没得 Tex?……点不出来
chenyunkun2008 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 cpp2017 的回复:]
原来是Label


改成Convert.ToSingle((Label)GvRow.Cells[3].FindControl("C_WAGE")).Text)
其他都一样.

[/Quote]

哈哈,,顶顶,
cpp2017 2009-07-28
  • 打赏
  • 举报
回复
原来是Label


改成Convert.ToSingle((Label)GvRow.Cells[3].FindControl("C_WAGE")).Text)
其他都一样.
lihui123 2009-07-28
  • 打赏
  • 举报
回复
<Columns>
<asp:BoundField DataField="c_id" HeaderText="ID编号" />
<asp:BoundField DataField="INFO_NAME" HeaderText="所属部门" />
<asp:BoundField DataField="p_name" HeaderText="姓名" />
<asp:TemplateField HeaderText="月薪" >
<ItemTemplate>
<asp:Label ID="c_wage" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="缺勤天数">
<ItemTemplate>
<asp:Label ID="c_absence_count" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="出差补贴">
<ItemTemplate>
<asp:Label ID="C_ALLOWANCE_ERRAND"runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="奖金1">
<ItemTemplate>
<asp:Label ID="c_bonus1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="奖金2">
<ItemTemplate>
<asp:Label ID="c_bonus2" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="奖金3">
<ItemTemplate>
<asp:Label ID="c_bonus3" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="其它扣款">
<ItemTemplate>
<asp:Label ID="c_deduct" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="社会保险">
<ItemTemplate>
<asp:Label ID="c_insure" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="操 作">
<ItemStyle HorizontalAlign="Center"/>
<ItemTemplate>
<asp:ImageButton ID="lb_edit" runat="server" ToolTip="保存此工资详细信息" ImageUrl="../../Images/user7_(edit)_16x16.gif" />
<asp:HyperLink ID="lb_mob" runat="server" ToolTip="查看详细工资信息" ImageUrl="../../Images/user7_16x16.gif"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>


这就是Gridview里面的Column
cpp2017 2009-07-28
  • 打赏
  • 举报
回复
TemplateFiled到底是什么?贴出来看看?
xsm545 2009-07-28
  • 打赏
  • 举报
回复
顶..楼上已经有答案了

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧