Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从代码隐藏访问gridview中的超链接列_C#_Asp.net_Gridview_Hyperlink - Fatal编程技术网

C# 无法从代码隐藏访问gridview中的超链接列

C# 无法从代码隐藏访问gridview中的超链接列,c#,asp.net,gridview,hyperlink,C#,Asp.net,Gridview,Hyperlink,我想从代码隐藏中访问GridView的HyperLinkField列,但我无法这样做 我的数据集中有该列,但仍然无法使用它 我的HyperLinkField列名为Status 以下是我尝试过的: UltraWebGrid1.DataSource = ObjPriDsGrid; UltraWebGrid1.DataBind(); string StrPriStatus = ""; for (int IntPriI = 0; IntPriI < UltraWebGrid1.Rows.Co

我想从代码隐藏中访问GridView的
HyperLinkField
列,但我无法这样做

我的数据集中有该列,但仍然无法使用它

我的
HyperLinkField
列名为
Status

以下是我尝试过的:

UltraWebGrid1.DataSource = ObjPriDsGrid;
UltraWebGrid1.DataBind();

string StrPriStatus = "";

for (int IntPriI = 0; IntPriI < UltraWebGrid1.Rows.Count; IntPriI++)
{
    if (UltraWebGrid1.Rows[IntPriI].Cells[6].Text.Trim() != null)
    {
        StrPriStatus = UltraWebGrid1.Rows[IntPriI].Cells[6].Text.Trim();
    }
    else
    {

    }
    if (StrPriStatus == "5")
    {
        UltraWebGrid1.Rows[IntPriI].Cells[8].Text = ""; // Not getting status column here
    }
}
UltraWebGrid1.DataSource=ObjPriDsGrid;
UltraWebGrid1.DataBind();
字符串StrPriStatus=“”;
对于(IntPriI=0;IntPriI
以下是我的GridView:

<asp:GridView ID="UltraWebGrid1" ShowHeader="true" runat="server" AutoGenerateColumns="false"
    DataKeyNames="mkey" OnRowDataBound="Grid_RowDataBound" Width="98%" Height="30%"
    PageSize="10" AllowPaging="true" OnPageIndexChanging="Grid1_PageIndexChanging"
    ShowFooter="true" CssClass="Grid">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <img alt="" style="cursor: pointer" src="../../../Images/plus.png" />
                <asp:Panel ID="pnlGrid" runat="server" Style="display: none">
                    <asp:GridView ID="Grid2" runat="server" AutoGenerateColumns="false" Width="600px"
                        CssClass="ChildGrid">
                        <Columns>
                            <asp:BoundField ItemStyle-Width="80px" DataField="RefMkey" HeaderText="Mkey" />
                            <asp:BoundField ItemStyle-Width="150px" DataField="CurrentUser" HeaderText="Current User" />
                            <asp:BoundField ItemStyle-Width="180px" DataField="Department" HeaderText="Current Department" />
                            <asp:BoundField ItemStyle-Width="100px" DataField="remarks" HeaderText="Remarks" />
                        </Columns>
                    </asp:GridView>
                </asp:Panel>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField ItemStyle-Width="0px" DataField="mkey" Visible="false" HeaderText="Mkey" />
        <asp:BoundField ItemStyle-Width="8%" DataField="Doc_No" HeaderText="IW/ No" />
        <asp:BoundField ItemStyle-Width="10%" DataField="Doc_Date" HeaderText="IW/ Date" />
        <asp:BoundField ItemStyle-Width="12%" DataField="DocType" HeaderText="Doc type" />
        <asp:BoundField ItemStyle-Width="15%" DataField="Party_Name" HeaderText="Party Name" />
        <asp:BoundField ItemStyle-Width="0" Visible="true" DataField="Status_Flag" HeaderText="Status" />
        <asp:BoundField ItemStyle-Width="10%" DataField="LastAction_datetime" HeaderText="Last Action Date" />
        <asp:BoundField ItemStyle-Width="10%" DataField="CurrStatus" HeaderText="Current Status" />
        <asp:BoundField ItemStyle-Width="10%" DataField="Type_desc" HeaderText="Resp Dept" />
        <asp:BoundField ItemStyle-Width="12%" DataField="UserName" HeaderText="Resp User" />
        <asp:BoundField ItemStyle-Width="8%" DataField="No_Of_Days" HeaderText="No of days" />
        <asp:HyperLinkField ItemStyle-Width="5%" DataNavigateUrlFields="Mkey, Status, Doc_No"
            DataNavigateUrlFormatString="~/Administration/Dispatch/Inward/FrmInwardNextAction.aspx?Inward_mkey={0}&Status={0}&IWNO={0}"
            HeaderText="Status" DataTextField="Status" Target="_blank" />
        <asp:HyperLinkField ItemStyle-Width="5%" DataNavigateUrlFields="Mkey, Status, Doc_No"
            HeaderText="View" DataTextField="View" Target="_blank" DataNavigateUrlFormatString="~/Administration/Dispatch/Inward/InwardDocDetails.aspx?Key={0}&Status={0}&IWNO={0}" />
    </Columns>
</asp:GridView>

你能这样试试吗

if (StrPriStatus == "5")
{
   HyperLink HyperLinkObj = (HyperLink)UltraWebGrid1.Rows[IntPriI].Cells[12].Controls[0];
   HyperLinkObj.Text = "";
}

HyperLinkField和CheckBoxField等列的行为与BoundField稍有不同。它们不仅仅包含像BoundField这样的文本。你必须在细胞内获得控制权。您可以使用
controls
集合获取单元格的子控件。我们知道,特别是对于
超链接字段
,超链接将是集合中的第一个控件

HyperLink hyp = (HyperLink)UltraWebGrid1.Rows[IntPriI].Cells[12].Controls[0];

我有点困惑。第8列是名为“当前状态”的
BoundField
,但第12列是名为“状态”的
HyperLinkField
。您实际要获取哪个状态列?现在,您要看的是第8列,它不是超链接。@j.f:我说的是第
12列
,我刚才在代码隐藏中添加了第8列来检查。当我调试
UltraWebGrid1.Rows[IntPriI].Cells[12].Text
for
12
时,我得到了非常好的结果!很高兴我能帮忙。