简体   繁体   English

Datagrid获取所选值(删除xml节点)

[英]Datagrid getting selected value (delete xml node)

Lets assume there are 2 columns in my datagrid: 假设我的datagrid中有2列:

    <asp:View ID="viewRemove" runat="server">
        <asp:DataGrid ID="dgRemove" runat="server" AutoGenerateColumns="False" OnDeleteCommand="dg_DeleteCommand">
            <Columns>
                <asp:BoundColumn DataField="name" HeaderText="names" />
                <asp:ButtonColumn ButtonType="PushButton" Text="Delete" CommandName="Delete" ></asp:ButtonColumn>
            </Columns>
        </asp:DataGrid>  
    </asp:View>

The first column displays names from a xml file and the button column just hold delete buttons so i can delete the corresponding item to the left of it (1st column). 第一列显示的是xml文件中的名称,而按钮列仅保留删除按钮,因此我可以删除其左侧的相应项目(第一列)。

How exactly can i retrieve/pass this selected value to a function? 我如何才能准确地将选定的值检索/传递给函数? In other words when i press the button to the right of the name, it passes the value so i can work with that to remove the corresponding xml node. 换句话说,当我按下名称右侧的按钮时,它会传递值,这样我就可以使用它来删除相应的xml节点。 (using XPath) (使用XPath)

    XmlDocument XMLDoc = new XmlDocument();
    XMLDoc.Load(file);
    XPathNavigator nav = XMLDoc.CreateNavigator();

    var node = nav.SelectSingleNode("/root/name['" + ??? + "']");
    node.DeleteSelf();
    XMLDoc.Save(file);

Thanks. 谢谢。

<asp:TemplateColumn HeaderText="Some Button">
   <ItemTemplate>
   <asp:LinkButton id="LinkButton1" runat="server" CommandArgument='
<# Eval   ("name") %>' >LinkButton</asp:LinkButton>
   </ItemTemplate>
</asp:TemplateColumn>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM