简体   繁体   English

如何从ASP.NET C#中的GridView获取单击的超链接行相邻单元格值

[英]How to get clicked hyperlink row adjacent cell value from GridView in ASP.NET C#

I'm working with one of my projects in C# ASP.NET. 我正在使用C#ASP.NET中的一个项目。 I have a GridView in webform page which is fetching data from database. 我在Webform页面中有一个GridView ,它正在从数据库中获取数据。 it has three columns Checkbox , DeptId and DeptName . 它具有CheckboxDeptIdDeptName三列。 DeptName is in hyperlink field i need that when user clicks deptName hyperlink its DeptId must be saved to a string and passed to other class as a parameter of selected department.i am confused how to do that !! DeptNamehyperlink字段中,我需要当用户单击deptName超链接时,它的DeptId必须保存为字符串并作为选定部门的参数传递给其他类。我很困惑该怎么做! Please Help me 请帮我

I did this but it didn't helped 我这样做了,但是没有帮助

 protected void DepartmentTable_SelectedIndexChanged(object sender, EventArgs e)
 {
      string name = DepartmentTable.SelectedRow.Cells[0].Text.ToString();
      Departmentlist obj = new Departmentlist();
      obj.setDeptid(name);
 }

HTML MARKUP CODE HTML标记代码

<asp:GridView ID="DepartmentTable" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" DataSourceID="SqlDataSource1" Width="814px" CellSpacing="2" ForeColor="Black" DataKeyNames="DeptId" OnSelectedIndexChanged="DepartmentTable_SelectedIndexChanged">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="DeptId" HeaderText="DeptId" SortExpression="DeptId" ReadOnly="True" InsertVisible="False" />
                    <asp:TemplateField HeaderText="DeptName">
                        <ItemTemplate>
                            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("DeptId", "Departmentlist.aspx?DeptId={0}") %>' Text='<%# Eval("DeptName") %>'></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <FooterStyle BackColor="#CCCCCC" />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                <PagerStyle ForeColor="Black" HorizontalAlign="Left" BackColor="#CCCCCC" />
                <RowStyle BackColor="White" />
                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="Gray" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#383838" />
            </asp:GridView>

You need to cast the control as a hyperlink and get thje text of the hyperlink control. 您需要将控件强制转换为超链接,并获取超链接控件的文本。 Something like: 就像是:

string name = ((HyperLink)DepartmentTable.SelectedRow.Cells[0].Controls[0]).Text; 字符串名称=((HyperLink)DepartmentTable.SelectedRow.Cells [0] .Controls [0])。Text;

暂无
暂无

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

相关问题 使用C#在asp.net中的gridview中单击该行的超链接字段时,检索该行的值 - Retrieve a value of a row when clicked hyperlink field of that row in a gridview in asp.net using c# 如何将值存储在gridview asp.net C#中的超链接所选择的行中? - How to store value in hyperlink link selected row in gridview asp.net C#? 如何从asp.net C#的GridView中的特定单元获取价值? - How to get value from a specific cell in a gridview asp.net c#? 从 GridView asp.net c# 中选择一个单元格值 - Select a cell value from GridView asp.net c# 如何在C#ASP.NET中获取超链接值 - How to get hyperlink value in c# ASP.NET 如何从asp.net C#Web窗体应用程序中的GridView中将selectedrow单元格值获取到电子邮件正文中? - How to get selectedrow cell value from a gridview into the body of an email in my asp.net c# web forms application? 如何在gridview c#asp.net中添加超链接到boundfield - How to add hyperlink to boundfield in gridview c# asp.net 按钮单击行时,在C#Gridview中获取单元格值 - Get Cell Value in C# Gridview when Button clicked on row 如何在ASP.NET C#WebForm中的文本框和下拉列表的GridView页脚行中获取值 - How Can I get the value in the gridview footer row of textbox and dropdownlist in asp.net c# webform 如何在C#ASP.NET中从gridview的页脚行中找到文本框的值 - How to find the value of textbox from the footer row of gridview in C# ASP.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM