0

私は、そのUpdatePanel中にGridView、そしてその中にRepeater。コメントを追加するボタンがあります。このボタンはポストバックしますが、idは関数コードビハインドを実行しません。これが私のコードです

<updatepanel>
    <gridview>
        <repeater>
            <asp:Button ID="kitapVarYorumEkle" runat="server"  
                 CommandArgument='<%#Eval("id") %>' 
                 CommandName='<%# GridView1.Rows.Count.ToString() %>' 
                 Text="Yorum ekle" class="blueButton" 
                 OnClick="kitapVarYorumEkle_Click"  />
        </repeater>
    </gridview>
</updatepanel>

js内のコードは次のとおりです。

protected void kitapVarYorumEkle_Click(object sender, EventArgs e)
{
        kitapVarYorum temp = new kitapVarYorum();

        if (Session["id"] != null)
        {
            temp.uyeId = Convert.ToInt32(Session["id"]);
        }

        Button btn = (Button)sender;
        temp.kitapVarId = Convert.ToInt32(btn.CommandArgument);

        string text = "";

        GridViewRow row = GridView1.Rows[Convert.ToInt32(btn.CommandName)];

        if (row != null)
        {
            TextBox txt = row.FindControl("txtYorum") as TextBox;

            if (txt != null)
            {
                text = txt.Text;
            }
        }

        temp.icerik = text;
        var db = Tools.DBBaglanti();
        db.kitapVarYorums.InsertOnSubmit(temp);
        db.SubmitChanges();

        // Page.Response.Redirect(Page.Request.Url.ToString(), true);
    }
}

私はコントロールの外でそれを試しました、そしてそれは働きます

4

1 に答える 1

0

ItemCommandアプローチを試しましたか?

<asp:Button  
     CommandArgument='<%#Eval("id") %>'
     CommandName="yourCommandNameOfChoice" 
     Text="Yorum ekle" 
     ID="kitapVarYorumEkle" 
     class="blueButton" runat="server"  
     OnClick="kitapVarYorumEkle_Click"  />

次に、リピーターのイベントを追加ItemCommandします。

 protected void yourRepeater_ItemCommand(object source , RepeaterCommandEventArgs e)
 {
     switch(e.CommandName)
     {
           case "yourCommandNameOfChoice":
               // Your Code Here 
               break;
     }
 }
于 2012-04-26T05:59:35.530 に答える