Grid View内的DataList [英] DataList inside Grid View

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

问题描述



我在用户控件&中有以下代码模板我想在我勾选或取消选中数据列表和内部的复选框时触发复选框更改事件.此数据列表在网格视图内是实习生.

希望能尽快得到答复

Hi,

I have below code template in user control & I want check box changed event to be fired when ever i check or uncheck checkbox which is inside datalist & this datalist is intern inside grid view.

Hope for the quick response

<pre lang="xml"><asp:GridView ID="gvSpecification" runat="server" AutoGenerateColumns="false" RepeatLayout="Table"
           OnRowDataBound="gvSpecification_RowDataBound" Width="100%" ItemStyle-CssClass="item-box">
           <Columns>
               <asp:TemplateField>
                   <ItemTemplate>
                       <div class="sub-category-item">
                           <h2 class="category-title">
                               <asp:Label ID="specification" runat="server"></asp:Label>
                           </h2>
                           <div>
                               <asp:DataList ID="dlOption" runat="server" OnItemCommand="dlOption_ItemCommand" RepeatColumns="2"
                                   Width="100%" RepeatDirection="Vertical">
                                   <ItemTemplate>
                                       <asp:CheckBox ID="chkOpt" runat="server" Text=''<%# Eval("Name") %>'' />
                                   </ItemTemplate>
                               </asp:DataList>
                           </div>
                       </div>
                   </ItemTemplate>
               </asp:TemplateField>
           </Columns>
       </asp:GridView>







推荐答案

此链接可能会对您有所帮助..
http://www.java2s.com/Code/JavaScript/Form-Control/ACheckboxandanonClickeventHandler.htm [^ ]
This link might help you..
http://www.java2s.com/Code/JavaScript/Form-Control/ACheckboxandanonClickeventHandler.htm[^]


尝试通过以下方式查找..

try to find out in the following way..

protected void repOrder_OnItemCreated_drdFill(object sender, RepeaterItemEventArgs e)
{
  CheckBox chk = (CheckBox)e.Item.FindControl("chkbxOrder");
  chk.CheckedChanged += new EventHandler(CheckedChanged);
}







private void CheckedChanged(object sender, EventArgs e)
      {
        CheckBox cb = (CheckBox)sender;
        try
        {
            My Code
        }
        catch (Exception ex)
        {
        }
}


您好

您可以这样尝试

Hi

You may try like this

<asp:CheckBox AutoPostBack="true" OnCheckedChanged="chkOpt_Changed" itemId='<%# Container.ItemIndex %>'  ID="chkOpt" runat="server" Text='<%# Eval("Name") %>'  />

.

如果要访问包含复选框的行,则一种方法是使用自定义属性,如我在ItemId上方所示.其他选项是通过Parent属性.

例如在检查更改事件中

.

If you want to access the row where the checkbox included then one way is using the custom attribute as I shown above the ItemId. Other option is through the Parent property.

For example in the check changed event

protected void chkOpt_Changed(object sender, EventArgs e)
 {
     CheckBox chk = (CheckBox)sender;
     //get datalist row id from the custom attribute
     int rowId = Convert.ToInt32(chk.Attributes["itemId"]);

     //get the parent gridview row id through parent hierarchy (in your markup hierarchy)
     GridViewRow row = (GridViewRow)chk.Parent.Parent.Parent.Parent;

     int parentGridRowIndex = row.RowIndex;


 }



祝你好运



Good luck


这篇关于Grid View内的DataList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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