很多的朋友都问过我这个问题,我就在这里把它写出来算了。在我们的WEB程序中,很多的时候都要实现多选和单选的操作,

在GridView和Repeater中。其实它们实现起来很相似。多选网上提供了很多的解决方案:如

  只要设置CommandName值的,可直接在ItemCommand事件中获取CommandName或者CommandArgument,

  如果是模板中有文本框之类的,把文件框的AutoPostBack属性设置为True,然后在TextChanged事件中编写如下代码:
C#代码
  1.  TextBox t = (TextBox)sender;    
  2. RepeaterItem ri = (RepeaterItem)t.NamingContainer;    
  3. string itemid =((HiddenField)ri.FindControl("hdfItemId")).Value;   
形式和GridView一样,只需记住GridView是GridViewRow,而Repeater是RepeaterItem  。

      很多的朋友在实现单选却迷糊了起来,其实单选比起多选来更容易的实现,如:

            <asp:Repeater runat="server" ID="rptFileList">
                <ItemTemplate>
                    <tr>
                        <td>
                            <input type="radio" )) %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>

 我们在前台界面可以添加

<asp:TextBox ID="txtID" runat="server" Text="" style="display:none;"></asp:TextBox>

JS代码如:

    function Set(obj) {
        document.getElementById("<%=txtID.ClientID %>").value = obj.value;
    }

 这样,后台我们就可以很方便的获取到选择行的ID值了。

相关文章:

  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-03-08
  • 2021-10-02
  • 2021-11-11
  • 2021-04-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案