0

私は AutoGenerateEditButton="true" でこのグリッドビューを持っています:

<asp:GridView ID="myGridview" runat="server" 
    ShowFooter="True" 
    AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" 
    AutoGenerateColumns="False" AllowSorting="True" DataKeyNames="id" DataSourceID="odsVolumeSearch" OnRowUpdating="myGridview_RowUpdating">
    <Columns>
        <asp:BoundField DataField="id" HeaderText="id" Visible="false" InsertVisible="False" ReadOnly="True" SortExpression="id" />
        <asp:BoundField DataField="Date" HeaderText="date" SortExpression="Date" ReadOnly="True" />
        <asp:BoundField DataField="Items" HeaderText="Items" SortExpression="Items" />            
    </Columns> 
</asp:GridView>

これは私のobjectDataSourceです:

<asp:ObjectDataSource ID="myOds" runat="server" 
    DeleteMethod="myDeleteMethod" SelectMethod="mySelectMethod" 
    TypeName="TheirLocation.sqlDataLayer" UpdateMethod="myUpdateMethod">
    <DeleteParameters>
        <asp:Parameter Name="id" Type="Int32" />
    </DeleteParameters>
    <SelectParameters>
        <asp:Parameter Name="fromDate" Type="DateTime"/>
        <asp:Parameter Name="toDate" Type="DateTime"/>
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="id" Type="Int32" />
        <asp:Parameter Name="volume" Type="Int32" />
    </UpdateParameters>
</asp:ObjectDataSource>

そして、この混乱は私の更新イベントハンドラーです:

protected void gvVolumeList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = gvVolumeList.Rows[e.RowIndex];
    String debugString = ((TextBox)(row.Cells[1].Controls[0])).Text;
    Response.Write("<script>alert('" + debugString + "');</script>");
}

テキストボックスから値を取得してアラートに表示しようとしていますが、修正できません。私はさまざまなことを試し、狂ったようにグーグルで検索しましたが、値を取得できません

編集

問題は、セル内のテキストボックスではなく、セルからテキストを取得していることだと思います。まだ何をすべきかわからない

4

3 に答える 3

1
protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {    
    GridViewRow row = TaskGridView.Rows[e.RowIndex];
    String str = ((TextBox)(row.Cells[2].Controls[0])).Text;
  }
于 2013-07-29T10:22:37.617 に答える
1

グリッドビューから Id を取得しようとしている場合!! バインドされたフィールドの可視性を false と宣言した場合、バインドされたフィールドはレンダリングされないため、使用してその値を取得することはできません

  String debugString = ((TextBox)(row.Cells[1].Controls[0])).Text;

そして、セルインデックスは1からではなく0から始まります(IDを取得しようとしている場合)。gridview の RowCommand を使用するか、 Id プロパティを作成することをお勧めしますvisible ="true"

- - - - - - - - - - - - - また - - - - - - - - - - - - ----- テンプレート フィールドを使用

 <asp:TemplateField>
            <ItemTemplate>
                <asp:HiddenField ID="HiddenField1" runat="server" 
                    Value='<%# Eval("Id") %>' />
                 ....
            </ItemTemplate>

コードビハインド

if (row.RowType == DataControlRowType.DataRow)
      {
       HiddenField Id = (HiddenField)row.Cells[0].FindControl("HiddenField1");

       }
于 2013-07-26T15:56:40.923 に答える
0

これは、行 Update でコントロール値を取得する方法です。

 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
    GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
    //int id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
    TextBox tname = (TextBox)row.FindControl("nam");
   //to get value of first cell
    string str = row.Cells[0].Text.ToString();
 }
于 2013-07-26T12:35:54.970 に答える