我正在尝试创建嵌套评论。下面的代码给了我索引超出范围。必须是非负数且小于集合的大小。参数名称:索引
protected void GridViewRowCommand(Object sender, GridViewCommandEventArgs e)
{
var scrapId = Int32.Parse(e.CommandArgument.ToString());
switch (e.CommandName)
{
case "comment":
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = GridViewUserScraps.Rows[index];
TextBox txtcomment = (TextBox)GridViewUserScraps.Rows[index].FindControl("txtcomment");
string postcomment = "Insert INTO comment (FromId,ToId,PostId,CommentMsg) VALUES('" + Session["UserId"].ToString() + "','" + Request.QueryString["Id"].ToString() + "','" + scrapId + "','"+txtcomment.Text+"')";
dbClass.ConnectDataBaseToInsert(postcomment);
break;
}
}
数据键名是 ..DataKeyNames="ScrapId"
我想传递与我单击发布的按钮位于同一行的文本框的值。
按钮:
<asp:Button ID="Button1" runat="server" Text="Comment" CommandName="comment"
CommandArgument='<%# Eval("ScrapId")%>' />