2016-08-10 8 views
1

GridViewのHyperLinkField列にコードの背後からアクセスしたいが、そうすることができない。後ろのコードからgridview内のハイパーリンク列にアクセスできない

私のデータセットには列がありますが、まだ使用できません。

私のHyperLinkField列の名前はStatusです。ここで

img

私が試したものです。ここで

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 
    } 
} 

は私の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> 
+0

私は少し混乱しています。列8は「現在のステータス」という名前の「BoundField」ですが、列12は「ステータス」という名前の「HyperLinkField」です。実際に取得しようとしているステータス列はどれですか?今、あなたはハイパーリンクではない第8列に行きます。 –

+0

@ j.f .:私は12行目について話していますが、8行目のコードでチェックするように追加しました。私が 'UltraWebGrid1.Rows [IntPriI] .Cells [12] .Text'を' 12'のためにデバッグしたとき、私は空白として – BNN

答えて

1

列のようにそれを試すことができますperLinkFieldとCheckBoxFieldは、BoundFieldとは少し異なる動作をします。 BoundFieldのようなテキストだけではありません。セル内でコントロールを取得する必要があります。 Controlsコレクションを使用して、セルの子コントロールを取得できます。具体的にはHyperLinkFieldの場合、HyperLinkがコレクションの最初のコントロールになることがわかっています。

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

という値を得ました。それは魅力のように働いた。多くの感謝 – BNN

+0

素晴らしい!お役に立てて嬉しいです。 –

0

あなたはHyのようなこの

if (StrPriStatus == "5") 
{ 
    HyperLink HyperLinkObj = (HyperLink)UltraWebGrid1.Rows[IntPriI].Cells[12].Controls[0]; 
    HyperLinkObj.Text = ""; 
} 
関連する問題