动态地将链接添加到datagridview [英] Adding Link to datagridview dynamically

查看:67
本文介绍了动态地将链接添加到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已填充7列的datagridview.现在我想向1列(即数字)添加链接.单击此链接后,它将显示基于该数字的详细信息.

I have my datagridview filled which have 7 columns.Now I want to add link to 1 column(i.e Number).After clicking this link,it will display details based on that number.
Please can any1 help me out?

推荐答案

Dim lnk As New DataGridViewLinkColumn()
       DataGridView1.Columns.Add(lnk)
       lnk.HeaderText = "Link Data"
       lnk.Name = "Link"
       lnk.Text = "Link"
       lnk.UseColumnTextForLinkValue = True




并使用DataKeyNames(PrimaryKey索引)和列的值来获取数据以显示结果.


http://msdn.microsoft.com/en-us/library/system. windows.forms.datagridviewlinkcolumn.aspx [ ^ ]




And Use the DataKeyNames(PrimaryKey index) and the value of the column to get the data to display the results.


http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewlinkcolumn.aspx[^]


<asp:GridView ID="GridView1" runat="server" EnableViewState="false" AutoGenerateColumns="False"

    ShowFooter="True" DataKeyNames="VendorId" AllowPaging="True" CellPadding="3"

    PageSize="5" BackColor="White" BorderColor="White" BorderStyle="Ridge" CellSpacing="1"

    Width="100%" BorderWidth="2px" GridLines="None" AllowSorting="true"  OnRowDataBound="gv_RowDataBound">
    <Columns>
        <asp:TemplateField HeaderText="Edit" ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="complain_no" runat="server" CausesValidation="False" CommandName="complain_no"

                    Text="complain_no"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="date" SortExpression="VendorFName">

            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("date") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="name" SortExpression="VendorLName">
            <ItemTemplate>
                <asp:Label ID="name" runat="server" Text='<%# Bind("name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        
    </Columns>
    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
    <PagerStyle ForeColor="Black" HorizontalAlign="Right" BackColor="#C6C3C6" />
    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
</asp:GridView>



protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       // Use debug and see the column which u got. 
       // check the column. if its linkbutton column then
       // do your code here.

    }

}


在我们的设计模式中,右键单击gridview,然后单击编辑列,然后添加列.在那里您可以找到DataGridViewLinkColumn.选择并申请,然后确定.
并从属性"窗格中将CellClick事件添加到网格中.代码后面的代码如下.

In ur design mode right click on gridview and click on edit columns then add column. there you can find DataGridViewLinkColumn. chose and apply then ok.
and add CellClick event to the grid from Properties pane. There after the code behind code as follows.

private void DgvView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 0)//if ur link columnIndex (complain_no ColumnIndex) is zero 
                {
                  // Display your data here
                }
            } 
            catch(Exception e)
            {
            }
         }




//在vb.net中也执行相同的步骤.因此请转换为vb.net代码.




// same procedure in vb.net also. so convert into vb.net code.


这篇关于动态地将链接添加到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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