错误:无法将类型为“System.Web.UI.WebControls.TextBox”的对象强制转换为“System.Web.UI.WebControls.Label” [英] error:Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.Web.UI.WebControls.Label'
问题描述
<%@ Page Title =Language =C#MasterPageFile =〜/ SA_MASTER_reports.masterAutoEventWireup =trueCodeFile =Default.aspx.csInherits =_ Default%>
< asp:Content ID =Content1ContentPlaceHolderID =headRunat =Server>
< style type = text / css>
.style1
{
身高:25px;
}
< / style>
< asp:Content ID =Content2ContentPlaceHolderID =ContentPlaceHolder1Runat =Server>
style =border:medium groove#000000>
style =color:#0000FF; f ont-weight:粗体> < asp:Label ID =Lblerrrunat =serverText =Label> < asp:标签ID =Labelerr1runat =serverText =Label> | |
style =color: #0000FF; font-weight:bold> < asp:Label ID =Label8runat =serverText =State Code> | style =color:#0000FF; font-weight:bold> < asp:Label ID =Strunat =serverText =Label> |
style =color:#0000FF; font-weight:bold> < asp:Label ID =Label10runat =serverText =District> | style =color:#0000FF; font-weight:bold> < asp:Label ID =Dirunat =serverText =Label> |
style =color:#0000FF; font-weight:bold> < asp:Label ID =Label12runat =serverText =Panchayat Name> | style =color:#0000FF; font-weight:bold> < asp:Label ID =Panrunat =serverText =Label> |
style =color:#0000FF; font-weight:boldclass =style1> < asp:Label ID =Label14runat =serverText =Panchayat Code > | style =color:#0000FF; font-weight:boldclass =style1> < asp:Label ID =Pacrunat =serverText =Label> |
style =color:#0000FF; font-weight:bold> < asp:Label ID =Label16runat =serverText =From> | style =color:#0000FF; font-weight:bold> < asp:Label ID =Frrunat =serverText =Label> |
style =color:#0000FF; font-weight:bold> < asp:Label ID =Label18runat =serverText =至> | style =color:#0000FF; font-weight:bold> < asp:Label ID =Torunat =serverText =标签> |
style =border:medium groove#000000>
style =color:#0000FF; font-weight:bold> < asp:GridView ID =GridView1runat =serverBackColor =WhiteBorderColor =#999999 BorderStyle =NoneBorderWidth =1pxCellPadding =3AutoGenerateColumns =False ShowFooter =TrueOnRowCancelingEdit =GridView1_RowCancelingEdit OnRowEditing =GridView1_RowEditing Width =83%AllowPaging =True onpageindexchanging =GridView1_PageIndexChangingPageSize =5 GridLines =Vertical onrowupdating =GridView1_RowUpdating > < alternatingrowstyle backcolor =#DCDCDC> < columns>< asp :TemplateField HeaderText =S NOHeaderStyle-BackColor =& gt; < itemtemplate> < asp:Label ID =snorunat =serverText ='< %#Eval(s_no)%>'> < asp:TemplateField HeaderText =头部名称HOUSEHOLD> < itemtemplate> < asp:Label ID =Nmerunat =serverText =' <%#Eval(Nme_of_head_hh)%>'> < asp:TemplateField HeaderText =NO OF提供的工作日> < itemtemplate> < asp:Label ID =Norunat =serverText ='<%#Eval(No_of_days_provided)%>'> < asp:TemplateField HeaderText =没有提供任何工作但是没有提供> < itemtemplate> < asp:Label ID =Notrunat =serverText ='<%#Eval(No_of_days_nt_provided)%>'> ; < asp:TemplateField HeaderText =个人工作名称> < itemtemplate> < asp:Label ID =Noirunat =serverText ='<%#Eval(Name_of_indi_sanc)%>'> < asp:TemplateField HeaderText =JOB CARDNUMBERHeaderStyle-BackColor =Green> < edititemtemplate> < asp:TextBox ID =Jc1runat =serverText ='<%#Eval(Job_card)%>'> < itemtemplate> < asp:Label ID =Jcrunat =serverText ='<%#Eval(Job_card)%>'> < HeaderStyle BackColor =Green>< / HeaderStyle> < asp:TemplateField HeaderText =通过社交审核填写的UNREGISTER DEMANDHeaderStyle-BackColor =Green> < edititemtemplate> < asp: TextBox ID =UDrunat =serverText ='<%#Eval(Unregister_demand_to_be)%>'> < itemtemplate> < asp:Label ID =udtrunat =serverText ='<%#Eval(Unregister_demand_to_be)%>'> < HeaderStyle BackColor =Green>< / HeaderStyle> < asp :TemplateField HeaderText =个人工作所需但尚未制裁HeaderStyle-BackColor =Green> & lt; edititemtemplate> < asp:TextBox ID =iwtrunat =serverText ='<%#Eval(Individual_work_req)%>'> < itemtemplate> < asp:Label ID =IWrunat =serverText ='<%#Eval(Individual_work_req )%>'> < HeaderStyle BackColor =Green>< / HeaderStyle> < asp:TemplateField HeaderText =SC ST其他未被标记为SC ST其他易受伤害的群体,因此在MIS上HeaderStyle-BackColor =Green> < edititemtemplate> < asp:TextBox ID =sctrunat =serverText ='<%#Eval(Sc_st_other)%> > < itemtemplate> < asp:Label ID =SCrunat =serverText ='< %#Eval(Sc_st_other)%>'> < HeaderStyle BackColor =Green>< / HeaderStyle> < asp:CommandField ShowEditButton =True/> < footerstyle backcolor =#CCCCCCforecolor =黑色> < HeaderStyle BackColor =#000084Font-Bold =TrueForeColor =白色/> < pagerstyle backcolor =#999999forecolor =黑色horizontalalign =中心> < rowstyle backcolor =#EEEEEEforecolor =黑色> < SelectedRowStyle BackColor =#008A8CFont-Bold =TrueForeColor =White/> < sortedascendingcellstyle backcolor =#F1F1F1> < sortedascendingheaderstyle backcolor =#0000A9> < sorteddescendingcellstyle backcolor =#CAC9C9> < sorteddescendingheaderstyle backcolor =#000065> < asp:SqlDataSource ID =SqlDataSource1runat =server ConnectionString = <%$ ConnectionStrings:hhConnectionString%> SelectCommand =SELECT * FROM [nrega111]> |
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Data;
使用System.Data.SqlClient;
使用System.Configuration;
public partial class _Default:System.Web.UI。页面
{
String district_name =;
String state_name =;
String panchayat_name = ;
String panchayat_code =;
String from_dt =;
String To_dt =;
public String state_code =;
DataTable dtt;
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender,EventArgs e)
{
Labelerr1.Text =;
Lblerr.Text =;
district_name = Con vert.ToString(Session [district_name2]);
state_code = Convert.ToString(Session [state_code_d2]);
panchayat_name = Convert.ToString(Session [ panchayat_name2]);
from_dt = Convert.ToString(Session [from_dt2]);
To_dt = Convert.ToString(Session [to_dt2]);
panchayat_code = Convert.ToString(Session [panchayat_code2]); ;
if(!Page.IsPostBack)
{
St.Text = state_name;
Di.Text = district_name;
Pan.Text = panchayat_name;
Pac.Text = panchayat_code;
Fr.Text = from_dt;
To.Text = To_dt;
DataTable ff = new DataTable();
ff = binddatasc();
GridView1.DataSource = ff;
GridView1.DataBind();
}
}
public DataTable binddatasc()
{
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings [hhConnectionString ] .ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText =select * from nrega111;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
return dt;
}
protected void GridView1_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)
{
try
{
GridView1.EditIndex = -1;
dtt = binddatasc();
if(dtt.Rows.Count == 0)
{
GridView1.Visible = false;
}
else
{
GridView1.Visible = true;
}
GridView1.DataSource = d tt;
GridView1.DataBind();
}
catch (例外情况)
{
Labelerr1.Text =错误:+ ex.Message;
}
}
protected void GridView1_RowEditing(object sender,GridViewEditEventArgs e)
{
try
{
foreach(GridView1.Rows中的GridViewRow行)
{
GridView1.EditIndex = e .NewEditIndex;
}
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
catch(例外情况)
{
Labelerr1.Text =错误:+ ex.Message;
}
}
protected void GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
试试
{
if(Page.IsValid)
{
socialAudit_BL vv = new socialAudit_BL();
SocialAudit_BE tt = new SocialAudit_BE();
标签Jc =(标签)GridView1。行[e.RowIndex] .FindControl(Jc);
标签udt =(标签)GridView1.Rows [e.RowIndex] .FindControl(UD);
标签IW =(Label)GridView1.Rows [e.RowIndex] .FindControl(IW);
Label SC =(Label)GridView1.Rows [e.RowIndex] .FindControl(SC);
TextBox Jc1 =(TextBox)GridView1.Rows [e.RowIndex] .FindControl(Jc1);
TextBox UD =(TextBox)GridView1.Rows [e。 RowIndex] .FindControl(udt);
TextBox iwt =(TextBox)GridView1.Rows [e.RowIndex] .FindControl(iwt);
TextBox sct =(TextBox)GridView1.Rows [e.RowIndex] .FindControl(sct);
tt.jobc_no = Jc1.Text;
tt.Unregs_deman_to_be_fill = udt.Text;
tt.Indi_work_desire_nt_sanstioned = sct.Text;
tt.Sc_st_other_whois_nt_tagg = sct.Text;
tt.state_code = St.Text;
tt.district_name = Di.Text;
tt.panchayat = Pan.Text;
tt.panchayat_code = Pac.Text;
tt.dt_from = Convert.ToDateTime(Fr.Text);
tt.dt_To = Convert.ToDateTime(To.Text);
socialAudit_BL audit11 = new socialAudit_BL();
audit11.updategrid1(tt,GridView1.DataKeys [e.RowIndex] .Values [0] .ToString());
Labelerr1.ForeColor = System.Drawing.Color.Green;
Labelerr1.Text =提交记录;
}
}
catch(例外情况)
{
Labelerr1.Text =错误:+ ex.Message;
}
终于
{
con.Close();
}
}
}
ConnectionStrings:hhConnectionString%>
SelectCommand =SELECT * FROM [nrega111]>
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web。 UI;
使用System.Web.UI.WebControls;
使用System.Data;
使用System.Data.SqlClient;
使用System.Configuration;
public partial class _Default:System.Web.UI.Page
{
String district_name =;
String state_name =;
String panchayat_name =;
String panchayat_code = ;
String from_dt =;
String To_dt = ;
public String state_code =;
DataTable dtt;
SqlConnection con = new SqlConnection ();
protected void Page_Load(object sender,EventArgs e)
{
Labelerr1.Text = ;
Lblerr.Text =;
district_name = Convert.ToString(Session [district_name2]);
state_code = Convert.ToString(Session [state_code_d2]);
panchayat_name = Convert.ToString(Session [panchayat_name2]);
from_dt = Convert.ToString(Session [ from_dt2]);
To_dt = Convert.ToString(Session [to_dt2]);
panchayat_code = Convert.ToString(Session [panchayat_code2]); ;
if(!Page.IsPostBack)
{
St.Text = state_name;
Di.Text = district_name;
Pan.Text = panchayat_name;
Pac.Text = panchayat_code;
Fr.Text = from_dt;
To.Text = To_dt;
DataTable ff = new DataTable();
ff = binddatasc();
GridView1.DataSource = ff;
GridView1.DataBind();
}
}
public DataTable binddatasc()
{
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings [hhConnectionString ] .ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText =select * from nrega111;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
return dt;
}
protected void GridView1_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)
{
try
{
GridView1.EditIndex = -1;
dtt = binddatasc();
if(dtt.Rows.Count == 0)
{
GridView1.Visible = false;
}
else
{
GridView1.Visible = true;
}
GridView1.DataSource = d tt;
GridView1.DataBind();
}
catch (例外情况)
{
Labelerr1.Text =错误:+ ex.Message;
}
}
protected void GridView1_RowEditing(object sender,GridViewEditEventArgs e)
{
try
{
foreach(GridView1.Rows中的GridViewRow行)
{
GridView1.EditIndex = e .NewEditIndex;
}
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
catch(例外情况)
{
Labelerr1.Text =错误:+ ex.Message;
}
}
protected void GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender,GridViewUpdateEventArgs e)
{
试试
{
if(Page.IsValid)
{
socialAudit_BL vv = new socialAudit_BL();
SocialAudit_BE tt = new SocialAudit_BE();
标签Jc =(标签)GridView1。行[e.RowIndex] .FindControl(Jc);
标签udt =(标签)GridView1.Rows [e.RowIndex] .FindControl(UD);
标签IW =(Label)GridView1.Rows [e.RowIndex] .FindControl(IW);
Label SC =(Label)GridView1.Rows [e.RowIndex] .FindControl(SC);
TextBox Jc1 =(TextBox)GridView1.Rows [e.RowIndex] .FindControl(Jc1);
TextBox UD =(TextBox)GridView1.Rows [e。 RowIndex] .FindControl(udt);
TextBox iwt =(TextBox)GridView1.Rows [e.RowIndex] .FindControl(iwt);
TextBox sct =(TextBox)GridView1.Rows [e.RowIndex] .FindControl(sct);
tt.jobc_no = Jc1.Text;
tt.Unregs_deman_to_be_fill = udt.Text;
tt.Indi_work_desire_nt_sanstioned = sct.Text;
tt.Sc_st_other_whois_nt_tagg = sct.Text;
tt.state_code = St.Text;
tt.district_name = Di.Text;
tt.panchayat = Pan.Text;
tt.panchayat_code = Pac.Text;
tt.dt_from = Convert.ToDateTime(Fr.Text);
tt.dt_To = Convert.ToDateTime(To.Text);
socialAudit_BL audit11 = new socialAudit_BL();
audit11.updategrid1(tt,GridView1.DataKeys [e.RowIndex] .Values [0] .ToString());
Labelerr1.ForeColor = System.Drawing.Color.Green;
Labelerr1.Text =提交记录;
}
}
catch(例外情况)
{
Labelerr1.Text =错误:+ ex.Message;
}
终于
{
con.Close();
}
}
}
Quote:'System.Web.UI.WebControls.TextBox'to type' System.Web.UI.WebControls.Label'
因此,您正在将
标签
转换为TextBox
。
逐行调试,找出你看到这个异常的确切位置。然后你可以实际更新那行代码。
Label Jc =(Label)GridView1.Rows [e.RowIndex] .FindControl( Jc);
// UD是一个文本框,无法将其转换为标签
< span class =code-comment> // < asp:textbox id =UDrunat =servertext =<%#Eval( Unregister_demand_to_be)%> xmlns:asp =#unknown>
// 标签udt =(标签) GridView1.Rows [e.RowIndex] .FindControl(UD);
// 更正的代码
标签udt =(标签)GridView1.Rows [e.RowIndex] .FindControl( UDT跨度>);
标签IW =(标签)GridView1.Rows [e.RowIndex] .FindControl( IW跨度>);
标签SC =(标签)GridView1.Rows [e.RowIndex] .FindControl( SC跨度>);
TextBox Jc1 =(TextBox)GridView1.Rows [e.RowIndex] .FindControl( Jc1跨度>);
// udt是一个无法将其转换为文本框的标签
// TextBox UD =(TextBox)GridView1.Rows [e.RowIndex] .FindControl(udt) ;
// 更正后的代码
TextBox UD =(TextBox )GridView1.Rows [e.RowIndex] .FindControl( UD);
TextBox iwt =(TextBox)GridView1.Rows [e.RowIndex] .FindControl( IWT跨度>);
TextBox sct =(TextBox)GridView1.Rows [e.RowIndex] .FindControl( sct跨度>);
<%@ Page Title="" Language="C#" MasterPageFile="~/SA_MASTER_reports.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style1
{
height: 25px;
}
</style>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
style="border: medium groove #000000">
style="color: #0000FF; font-weight: bold" > <asp:Label ID="Lblerr" runat="server" Text="Label"> <asp:Label ID="Labelerr1" runat="server" Text="Label"> | |
style="color: #0000FF; font-weight: bold" > <asp:Label ID="Label8" runat="server" Text="State Code"> | style="color: #0000FF; font-weight: bold" > <asp:Label ID="St" runat="server" Text="Label"> |
style="color: #0000FF; font-weight: bold" > <asp:Label ID="Label10" runat="server" Text="District"> | style="color: #0000FF; font-weight: bold" > <asp:Label ID="Di" runat="server" Text="Label"> |
style="color: #0000FF; font-weight: bold" > <asp:Label ID="Label12" runat="server" Text="Panchayat Name"> | style="color: #0000FF; font-weight: bold" > <asp:Label ID="Pan" runat="server" Text="Label"> |
style="color: #0000FF; font-weight: bold" class="style1" > <asp:Label ID="Label14" runat="server" Text="Panchayat Code"> | style="color: #0000FF; font-weight: bold" class="style1" > <asp:Label ID="Pac" runat="server" Text="Label"> |
style="color: #0000FF; font-weight: bold" > <asp:Label ID="Label16" runat="server" Text="From"> | style="color: #0000FF; font-weight: bold" > <asp:Label ID="Fr" runat="server" Text="Label"> |
style="color: #0000FF; font-weight: bold" > <asp:Label ID="Label18" runat="server" Text="To"> | style="color: #0000FF; font-weight: bold" > <asp:Label ID="To" runat="server" Text="Label"> |
style="border: medium groove #000000">
style="color: #0000FF; font-weight: bold" > <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" AutoGenerateColumns="False" ShowFooter="True" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" Width="83%" AllowPaging="True" onpageindexchanging="GridView1_PageIndexChanging" PageSize="5" GridLines="Vertical" onrowupdating="GridView1_RowUpdating" > <alternatingrowstyle backcolor="#DCDCDC"> <columns> <asp:TemplateField HeaderText="S NO" HeaderStyle-BackColor=> <itemtemplate> <asp:Label ID="sno" runat="server" Text='<%#Eval("s_no") %>'> <asp:TemplateField HeaderText="NAME OF HEAD OF HOUSEHOLD"> <itemtemplate> <asp:Label ID="Nme" runat="server" Text='<%#Eval("Nme_of_head_hh ") %>'> <asp:TemplateField HeaderText="NO OF DAYS OF WORK PROVIDED"> <itemtemplate> <asp:Label ID="No" runat="server" Text='<%#Eval(" No_of_days_provided") %>'> <asp:TemplateField HeaderText="NO OF DAYS WORK DEMANDED BUT NOT PROVIDED"> <itemtemplate> <asp:Label ID="Not" runat="server" Text='<%#Eval(" No_of_days_nt_provided") %>'> <asp:TemplateField HeaderText="NAME OF INDIVIDUAL WORK SANCTIONED"> <itemtemplate> <asp:Label ID="Noi" runat="server" Text='<%#Eval("Name_of_indi_sanc") %>'> <asp:TemplateField HeaderText="JOB CARDNUMBER" HeaderStyle-BackColor ="Green"> <edititemtemplate> <asp:TextBox ID="Jc1" runat="server" Text='<%#Eval("Job_card") %>'> <itemtemplate> <asp:Label ID="Jc" runat="server" Text='<%#Eval("Job_card") %>'> <HeaderStyle BackColor="Green"></HeaderStyle> <asp:TemplateField HeaderText="UNREGISTER DEMAND TO BE FILLED BY SOCIAL AUDIT" HeaderStyle-BackColor ="Green"> <edititemtemplate> <asp:TextBox ID="UD" runat="server" Text='<%#Eval("Unregister_demand_to_be") %>'> <itemtemplate> <asp:Label ID="udt" runat="server" Text='<%#Eval("Unregister_demand_to_be") %>'> <HeaderStyle BackColor="Green"></HeaderStyle> <asp:TemplateField HeaderText="INDIVIDUAL WORK DESIRED BUT NOT SANCTIONED" HeaderStyle-BackColor ="Green"> <edititemtemplate> <asp:TextBox ID="iwt" runat="server" Text='<%#Eval("Individual_work_req") %>'> <itemtemplate> <asp:Label ID="IW" runat="server" Text='<%#Eval("Individual_work_req") %>'> <HeaderStyle BackColor="Green"></HeaderStyle> <asp:TemplateField HeaderText="SC ST OTHER WHO IS NOT TAGGED AS SC ST OTHER VULNERABLE GROUP AS SO ON THE MIS" HeaderStyle-BackColor ="Green"> <edititemtemplate> <asp:TextBox ID="sct" runat="server" Text='<%#Eval(" Sc_st_other") %>'> <itemtemplate> <asp:Label ID="SC" runat="server" Text='<%#Eval(" Sc_st_other") %>'> <HeaderStyle BackColor="Green"></HeaderStyle> <asp:CommandField ShowEditButton="True" /> <footerstyle backcolor="#CCCCCC" forecolor="Black"> <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> <pagerstyle backcolor="#999999" forecolor="Black" horizontalalign="Center"> <rowstyle backcolor="#EEEEEE" forecolor="Black"> <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> <sortedascendingcellstyle backcolor="#F1F1F1"> <sortedascendingheaderstyle backcolor="#0000A9"> <sorteddescendingcellstyle backcolor="#CAC9C9"> <sorteddescendingheaderstyle backcolor="#000065"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:hhConnectionString %>" SelectCommand="SELECT * FROM [nrega111]"> |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
String district_name = "";
String state_name = "";
String panchayat_name = "";
String panchayat_code = "";
String from_dt = "";
String To_dt = "";
public String state_code = "";
DataTable dtt;
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
Labelerr1.Text = "";
Lblerr.Text = "";
district_name = Convert.ToString(Session["district_name2"]);
state_code = Convert.ToString(Session["state_code_d2"]);
panchayat_name = Convert.ToString(Session["panchayat_name2"]);
from_dt = Convert.ToString(Session["from_dt2"]);
To_dt = Convert.ToString(Session["to_dt2"]);
panchayat_code = Convert.ToString(Session["panchayat_code2"]); ;
if (!Page.IsPostBack)
{
St.Text = state_name;
Di.Text = district_name;
Pan.Text = panchayat_name;
Pac.Text = panchayat_code;
Fr.Text = from_dt;
To.Text = To_dt;
DataTable ff = new DataTable();
ff = binddatasc();
GridView1.DataSource = ff;
GridView1.DataBind();
}
}
public DataTable binddatasc()
{
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["hhConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from nrega111";
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
return dt;
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
try
{
GridView1.EditIndex = -1;
dtt = binddatasc();
if (dtt.Rows.Count == 0)
{
GridView1.Visible = false;
}
else
{
GridView1.Visible = true;
}
GridView1.DataSource = dtt;
GridView1.DataBind();
}
catch (Exception ex)
{
Labelerr1.Text = "Error :" + ex.Message;
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
foreach (GridViewRow row in GridView1.Rows)
{
GridView1.EditIndex = e.NewEditIndex;
}
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
catch (Exception ex)
{
Labelerr1.Text = "Error : " + ex.Message;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
if (Page.IsValid)
{
socialAudit_BL vv = new socialAudit_BL();
SocialAudit_BE tt = new SocialAudit_BE();
Label Jc = (Label)GridView1.Rows[e.RowIndex].FindControl("Jc");
Label udt = (Label)GridView1.Rows[e.RowIndex].FindControl("UD");
Label IW = (Label)GridView1.Rows[e.RowIndex].FindControl("IW");
Label SC = (Label)GridView1.Rows[e.RowIndex].FindControl("SC");
TextBox Jc1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Jc1");
TextBox UD = (TextBox)GridView1.Rows[e.RowIndex].FindControl("udt");
TextBox iwt = (TextBox)GridView1.Rows[e.RowIndex].FindControl("iwt");
TextBox sct = (TextBox)GridView1.Rows[e.RowIndex].FindControl("sct");
tt.jobc_no = Jc1.Text;
tt.Unregs_deman_to_be_fill = udt.Text;
tt.Indi_work_desire_nt_sanstioned = sct.Text;
tt.Sc_st_other_whois_nt_tagg = sct.Text;
tt.state_code = St.Text;
tt.district_name = Di.Text;
tt.panchayat = Pan.Text;
tt.panchayat_code = Pac.Text;
tt.dt_from = Convert.ToDateTime(Fr.Text);
tt.dt_To = Convert.ToDateTime(To.Text);
socialAudit_BL audit11 = new socialAudit_BL();
audit11.updategrid1(tt, GridView1.DataKeys[e.RowIndex].Values[0].ToString());
Labelerr1.ForeColor = System.Drawing.Color.Green;
Labelerr1.Text = "Record submitted";
}
}
catch (Exception ex)
{
Labelerr1.Text = "error:" + ex.Message;
}
finally
{
con.Close();
}
}
}
ConnectionStrings:hhConnectionString %>"
SelectCommand="SELECT * FROM [nrega111]">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
String district_name = "";
String state_name = "";
String panchayat_name = "";
String panchayat_code = "";
String from_dt = "";
String To_dt = "";
public String state_code = "";
DataTable dtt;
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
Labelerr1.Text = "";
Lblerr.Text = "";
district_name = Convert.ToString(Session["district_name2"]);
state_code = Convert.ToString(Session["state_code_d2"]);
panchayat_name = Convert.ToString(Session["panchayat_name2"]);
from_dt = Convert.ToString(Session["from_dt2"]);
To_dt = Convert.ToString(Session["to_dt2"]);
panchayat_code = Convert.ToString(Session["panchayat_code2"]); ;
if (!Page.IsPostBack)
{
St.Text = state_name;
Di.Text = district_name;
Pan.Text = panchayat_name;
Pac.Text = panchayat_code;
Fr.Text = from_dt;
To.Text = To_dt;
DataTable ff = new DataTable();
ff = binddatasc();
GridView1.DataSource = ff;
GridView1.DataBind();
}
}
public DataTable binddatasc()
{
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["hhConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from nrega111";
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
return dt;
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
try
{
GridView1.EditIndex = -1;
dtt = binddatasc();
if (dtt.Rows.Count == 0)
{
GridView1.Visible = false;
}
else
{
GridView1.Visible = true;
}
GridView1.DataSource = dtt;
GridView1.DataBind();
}
catch (Exception ex)
{
Labelerr1.Text = "Error :" + ex.Message;
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
foreach (GridViewRow row in GridView1.Rows)
{
GridView1.EditIndex = e.NewEditIndex;
}
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
catch (Exception ex)
{
Labelerr1.Text = "Error : " + ex.Message;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
dtt = binddatasc();
GridView1.DataSource = dtt;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
if (Page.IsValid)
{
socialAudit_BL vv = new socialAudit_BL();
SocialAudit_BE tt = new SocialAudit_BE();
Label Jc = (Label)GridView1.Rows[e.RowIndex].FindControl("Jc");
Label udt = (Label)GridView1.Rows[e.RowIndex].FindControl("UD");
Label IW = (Label)GridView1.Rows[e.RowIndex].FindControl("IW");
Label SC = (Label)GridView1.Rows[e.RowIndex].FindControl("SC");
TextBox Jc1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Jc1");
TextBox UD = (TextBox)GridView1.Rows[e.RowIndex].FindControl("udt");
TextBox iwt = (TextBox)GridView1.Rows[e.RowIndex].FindControl("iwt");
TextBox sct = (TextBox)GridView1.Rows[e.RowIndex].FindControl("sct");
tt.jobc_no = Jc1.Text;
tt.Unregs_deman_to_be_fill = udt.Text;
tt.Indi_work_desire_nt_sanstioned = sct.Text;
tt.Sc_st_other_whois_nt_tagg = sct.Text;
tt.state_code = St.Text;
tt.district_name = Di.Text;
tt.panchayat = Pan.Text;
tt.panchayat_code = Pac.Text;
tt.dt_from = Convert.ToDateTime(Fr.Text);
tt.dt_To = Convert.ToDateTime(To.Text);
socialAudit_BL audit11 = new socialAudit_BL();
audit11.updategrid1(tt, GridView1.DataKeys[e.RowIndex].Values[0].ToString());
Labelerr1.ForeColor = System.Drawing.Color.Green;
Labelerr1.Text = "Record submitted";
}
}
catch (Exception ex)
{
Labelerr1.Text = "error:" + ex.Message;
}
finally
{
con.Close();
}
}
}
Quote:'System.Web.UI.WebControls.TextBox' to type 'System.Web.UI.WebControls.Label'
So, somewhere you are converting a
Label
toTextBox
.
Debug line by line and find out where exactly you are seeing this exception. Then you can actually update that line of code.
Label Jc = (Label)GridView1.Rows[e.RowIndex].FindControl("Jc"); //UD is a textbox you can not convert it to label //<asp:textbox id="UD" runat="server" text="<%#Eval("Unregister_demand_to_be") %>" xmlns:asp="#unknown"> //Label udt = (Label)GridView1.Rows[e.RowIndex].FindControl("UD"); //corrected code Label udt = (Label)GridView1.Rows[e.RowIndex].FindControl("udt"); Label IW = (Label)GridView1.Rows[e.RowIndex].FindControl("IW"); Label SC = (Label)GridView1.Rows[e.RowIndex].FindControl("SC"); TextBox Jc1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Jc1"); //udt is a label you can not convert it to textbox //TextBox UD = (TextBox)GridView1.Rows[e.RowIndex].FindControl("udt"); //corrected code TextBox UD = (TextBox)GridView1.Rows[e.RowIndex].FindControl("UD"); TextBox iwt = (TextBox)GridView1.Rows[e.RowIndex].FindControl("iwt"); TextBox sct = (TextBox)GridView1.Rows[e.RowIndex].FindControl("sct");
这篇关于错误:无法将类型为“System.Web.UI.WebControls.TextBox”的对象强制转换为“System.Web.UI.WebControls.Label”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!