0

以下のようなグリッドがあります。

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" s                                      
                                    onrowcommand="GridView1_RowCommand">
  <Columns>
      <asp:ButtonField DataTextField="Name" HeaderText="Name" />
      <asp:BoundField DataField="ArrDate" DataFormatString="{0:MM/dd/yyyy}" 
                              HeaderText="Arr Date" />
      <asp:BoundField HeaderText="Dep Date" DataField="DepDate" 
                           DataFormatString="{0:MM/dd/yyyy}" />
      <asp:BoundField HeaderText="Mail" DataField="Mail" />
      <asp:BoundField HeaderText="Status" DataField="Status" />
      <asp:BoundField DataField="ResId" HeaderText="ResId" Visible="False" />                                        
  </Columns>
</asp:GridView>

コードビハインド:-

try
{
  string text = GridView1.Rows[2].Cells[5].Text;
  ScriptManager.RegisterStartupScript(this, GetType(), "Message", "alert('ResId = " + text  + ".');", true);             
}
catch { }

メッセージが表示されます - RegId =。

値を取得できません。そこで、RedId BoundField を可視に変更します。今、私は値を取得しました。

つまり、RegId =6 です。

私は今2つの問題を抱えています -

1) 非表示列の RegId 値を取得する方法。2)クリックした行の値を見つける方法...bzsコードでROWVALUEを変更できるのは..

 string text = GridView1.Rows[ROWVALUE].Cells[5].Text;
4

1 に答える 1

0

それは確かに正しい方法ではありません。これを実現するには、DataKeys の使用を検討することをお勧めします。現在のアプローチでは、グリッドに新しい列を追加すると、コードが失敗します。

  1. グリッドビューの DataKeys プロパティ内に RegId 列を追加します
  2. 次のように分離コードで現在の行のグリッドビュー データキーを参照します。

     int regId= Convert.ToInt32(YourGridview.DataKeys[rowIndex]["RegId"].ToString());
    
于 2012-07-24T05:46:37.097 に答える