给ID为自定义属性为手动更新一个网格复选框 [英] give the ID as a custom attribute to checkbox in a grid for manual update

查看:155
本文介绍了给ID为自定义属性为手动更新一个网格复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在ASP网更新我的复选框只值。

I like to update just the value of my checkbox in a asp grid.

所以我想我的ID绑定到复选框(但如何?),然后点击复选框中火code更新落后。

so i thought i bind the id to the checkbox ( but how?) and fire an update in code behind by clicking the checkbox.

但我怎么能得到的ID,并在那里我有这个ID绑定得到它在code。在事件背后?

but how can I get the ID, and where I have to bind this id to get it in code behind in the event?

感谢

推荐答案

下面就是我能够做到。 (请注意应该有这样做更简单的方法,我很新的ASP.NET)

Here is what I've managed to do. (Be aware there should be an easier way to do this. I'm very new to ASP.NET)

在这里,你有一个TemplateField在GridView。里面有一个UpdatePanel并且该复选框被里面。这样做是为了使文本框的检查后做了backgroung(阿贾克斯)。你可能不会需要它(的UpdatePanel)都没有。

Here you have a TemplateField in a GridView. Inside it there is an UpdatePanel and the CheckBox is inside it. This is done to make the checking of the TextBox do post in the backgroung (ajax). You might not need it (UpdatePanel) at all.

<asp:TemplateField HeaderText="Private" SortExpression="IsPrivate">
  <ItemTemplate>
    <asp:UpdatePanel ID="upIsPrivate" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
      <ContentTemplate>
        <asp:CheckBox ID="chkIsPrivate" runat="server" OnCheckedChanged="chkIsPrivate_CheckedChanged" AutoPostBack="true" />
      </ContentTemplate>
    </asp:UpdatePanel>
  </ItemTemplate>
</asp:TemplateField>

这是处理这一方法。请注意,我从包含复选框的GridViewRow获得ID:

And this is the method that handles this. Notice that I get the Id from the GridViewRow that contains the CheckBox:

GridViewRow行=(GridViewRow)((复选框)发送方).Parent.Parent.Parent.Parent;

protected void chkIsPrivate_CheckedChanged(object sender, EventArgs e)
{
  if (editMode)
  {
    GridViewRow row = (GridViewRow)((CheckBox)sender).Parent.Parent.Parent.Parent;
    Int32 id = (Int32)uxPhoneCallList.DataKeys[row.RowIndex]["Id"];
    CheckBox isPrivate = (CheckBox)row.FindControl("chkIsPrivate");

    PhoneCall phoneCall = PhoneCallManager.GetById(id);
    ...
  }
}

这篇关于给ID为自定义属性为手动更新一个网格复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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