1

私はドットネット2.0とc#を使用しています。

datagridの行を見つけて、関数の引数として渡す必要があるという要件があります。datagirdの行を見つけるためのコードを教えてください。ありがとう

4

3 に答える 3

1

あなたはで試すことができますItemDataBound event on your datagrid

void Item_Bound(Object sender, DataGridItemEventArgs e) 
{
      if((e.Item.ItemType == ListItemType.Item) || 
             (e.Item.ItemType == ListItemType.AlternatingItem))
         {
             var control = (Label)e.Item.FindControl("YourLabel");
             control.Text="pass your value";
         }
}


<asp:DataGrid id="DataGrid1" 
   runat="server" 
   AutoGenerateColumns="False" OnItemDataBound="Item_Bound">
   <Columns>
      <asp:TemplateColumn HeaderText="Sample">
         <ItemTemplate>
            <asp:Label id="YourLabel" runat="server"/>
         </ItemTemplate>
      </asp:TemplateColumn>
   </Columns>
</asp:DataGrid>
于 2012-10-29T13:16:26.713 に答える
0

データグリッドをItemDataBoundに配置し、イベントItemDataBound_clickを呼び出すだけです。

string rownumber = e.Item.FindControl("your id for the label") As Label 

これをパラメータとして使用する同等のデータ型を変換した後に使用します。

于 2012-10-29T13:23:26.027 に答える
0

gridview / datagrid行をループして、いくつかの基準が探しているものと一致するときに、好きなことを行うことができます。

    foreach (GridViewRow gvr in gvDemo.Rows) {
        if (gvr.DataItem != null) { 

            //depending on how or what you want to find 
            //check a key
            if (gvDemo.DataKeys[gvr.RowIndex].Values[0] == "xx") { 

            }
            //or a field value
            if (gvr.Cells[0].ToString() == "123") { 

            }

            //or first cast your row data item back to a known class
            CarBrand carBrand = (CarBrand)gvr.DataItem;
            if (carBrand.Name == "Porsche") { 
            //
            }

            //or pass the whole row to whatever function
            if (xx == yy) {
                DoSomething(gvr);
            }

        }
    }
于 2012-10-29T13:24:30.267 に答える