0

我有一个UpdatePanel,里面有一个GridView,里面有一个Repeater。有一个按钮可以添加评论。这个按钮 post back 但 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 回答