English 中文(简体)
背后没有修改《关于背后问题的格里多格检查箱》
原标题:Code behind not picking up changes made to Checkbox on a Gridview on postback

我有一个网格,有一个模板领域,把一个核对箱作为领域之一。

<asp:TemplateField HeaderText="Confirm Driver Details" FooterText="Confirm Driver Details">
    <ItemTemplate>
        <asp:CheckBox ID="chkConfirmDetails" runat="server" MaxLength="100" Width="50px" Enabled="false" Checked="true"></asp:CheckBox>
    </ItemTemplate>
</asp:TemplateField>

起初,这项检查没有进行。

用户上载一个文件,装入物体,然后输入电网。 关于罗达塔博迪活动,对数据进行了一些验证。 在某些情况下,如果部分验证失败,我想使检查箱能够安装,不打上标记。

CheckBox chkConfirmDetails = (CheckBox)e.Row.Cells[e.Row.Cells.Count - 2].FindControl("chkConfirmDetails");

//If this is enabled then we just need to check whether it is ticked or not
if (!chkConfirmDetails.Enabled)
{
    if (!ValidateDriver(_uploadData.DriverData[e.Row.DataItemIndex], out driverValidationMessage))
    {
        Label label = new Label();
        label.Text = "Details of this Driver cannot be found<br />Please double-check to see if the Driver Number, Date of Birth and PPSN are entered correctly<br />If you are sure you have the correct details entered tick this box to confirm";
        e.Row.Cells[e.Row.Cells.Count - 2].Controls.Add(label);
        e.Row.Cells[e.Row.Cells.Count - 2].BackColor = System.Drawing.Color.Yellow;
        ((TableRow)e.Row.Cells[e.Row.Cells.Count - 2].Parent).BackColor = System.Drawing.Color.Red;
        chkConfirmDetails.Enabled = true;
        chkConfirmDetails.Checked = false;
        _numberOfInvalidCells++;
    }
}

检查箱所有工作都得到罚款,而且没有计算。

用户然后可以选择打上盒子,确认细节正确,重新打字。 在数据网各行各有一顿,用户可点击履行这一职能。 因此,当用户点击验证字典时,上述代码被再次命名。 这一次检查箱能够使用,并且可能无法根据用户所做的情况加以衡量。

然而,当我通过采用“FindControl”方法查阅检查箱时,它仍然表现出“无能力”和“检查”(即使它能够做到,也没有按表格进行核对)。

谁能解释为什么会发生这种情况,以及如何使检查箱的实际状况?

EDIT

查阅请求。 表格.AllKeys数据,对电网格中大多数其他模板项目(文本箱和投放者)具有关键意义,但不是检查箱或验证的纽克

最佳回答

RowDataBound is only called if you DataBind the GridView to it s DataSource. That means you ve called it before. But as a result all changes made by the user are overridden.

因此,问题是,为什么你需要打上<条码>。 难道你能用一种办法,把所有GridViewRowsates起来吗?

因此,是否有具体理由请你使用

(CheckBox)e.Row.Cells[e.]。 Row.Cells.Count - 2].FindControl (“chkConfirmDetails”)

而不仅仅是

(CheckBox)e.Row.FindControl("chkConfirmDetails")?

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签