如何将数据绑定到LinkBut​​ton的不与其他绑定列干扰? [英] How to bind data to linkbutton without interfering with other boundfields?

查看:322
本文介绍了如何将数据绑定到LinkBut​​ton的不与其他绑定列干扰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有在页面数GridView的。首先GridView控件是可编辑的,第二个是没有的。第一gridview的具有包含超链接(LinkBut​​ton的)柱。第二个表应根据上述超链接的点击事件被加载。它像期待的超级链接的行为像一个按钮。可以这样做?

There are few gridviews in the page. First gridview is editable, second is not. First gridview has a column that has a hyperlink (linkbutton). The second table should be loaded based on the click event of above hyper link. It is like expecting the hyperlink to behave like a button. Can this be done?

为了去尝试,我不知道从哪里开始。我添加了一个超链接到第一个gridview的列。但是,为NavigationURL集是值得怀疑的我。

In order even try, I am not sure where to start. I added a hyperlink to the first gridview column. But what to set for the NavigationURL is doubtful to me.

有一个超链接控件的事件只有屈指可数。

There are only handful of events in a hyperlink control.

这些都不似乎做什么,我需要。任何教程是有价值的。

None of that seems to do what I need. Any tutorial is valuable.

更新:
网格标记code

Update: Gird markup code

<div id="schedule">
    <asp:GridView ID="gvSchedule" 
        runat="server" AutoGenerateColumns="false" 
        CssClass="Grid" 
        DataKeyNames="Employee ID, WOY, Location" 
        ShowHeader="false" 
        RowStyle-CssClass="rowstyle"
        onrowdatabound="gvSchedule_RowDataBound">
    <Columns>
 <asp:BoundField HeaderText="Staff" 
     DataField="E_Name" SortExpression="E_Name"  
     ItemStyle-Width="113" />
    </Columns>

    </asp:GridView>
    <br />
</div>

尝试了一个LinkBut​​ton按<一个href=\"http://stackoverflow.com/questions/21243070/how-to-add-hyperlink-to-boundfield-in-gridview-c-sharp-asp-net\">this这里的解决方案

<asp:TemplateField HeaderText="StaffClick" SortExpression="STOCK NO" ItemStyle-Width="50">
        <ItemTemplate>
           <asp:LinkButton ID="lblStaff" runat="server">Click</asp:LinkButton>
        </ItemTemplate>
        <HeaderStyle BackColor="Black" ForeColor="White" HorizontalAlign="Left"/>
        <ItemStyle HorizontalAlign="Left" />
        </asp:TemplateField>

使用这个code后,现在没有人用复选框的字段都装有rowbound事件。

After using this code, now none of the fields with checkboxes are loaded with rowbound event.

推荐答案

把一个LinkBut​​ton在你的GridView,并使用RowCommand动作设置什么应该发生的。一旦链接被点击,名为RowCommand事件被分派。您可以处理任何需要做的服务器端。

Put a LinkButton in your GridView, and use the "RowCommand" action to set what's supposed to happen. As soon as the link gets clicked, an Event called RowCommand is dispatched. You can handle whatever needs to happen server-side.

CommandArgument可以是你想传递给服务器端的功能,任何东西。

CommandArgument can be anything you want to pass to the function on the server side.

下面是一个例子:

 <asp:Button ID="btnViewmore"  
        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>
        " CommandName="More" runat="server" Text="View More" />

和服务器端你可以这样做(C#):

And on the server side you could do this (C#):

protected void gridMembersList_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "More")
    {
        int index = Convert.ToInt32(e.CommandArgument.ToString());
        // do something with your command and commandargument, like for instance, update the second gridview
    }
}  

这篇关于如何将数据绑定到LinkBut​​ton的不与其他绑定列干扰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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