ネストされたコメントを作成しようとしています。以下のコードは、インデックスが範囲外であったことを示しています。負ではなく、コレクションのサイズよりも小さい必要があります。パラメータ名:インデックス
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;
}
}
datakeynameは.です。DataKeyNames="ScrapId"
クリックして投稿するボタンと同じ行にあるテキストボックスの値を渡したいです。
ボタン:
<asp:Button ID="Button1" runat="server" Text="Comment" CommandName="comment"
CommandArgument='<%# Eval("ScrapId")%>' />