I have a textbox and a button submit in nested datalist, how do i insert the record using AJAX insert and let the record appear on insert
There is two datalists, one is the main datalist showing Discription the other is nexted comments
on the nexted comment there is a textbox and buton submit for submiting comments. So i want to be able to insert comment and when the comment is submitted i want to submitted comment to display without refreshing the page. Normally if data is inserted using Ajax it doesnt reflect immidiately unless the page is refreshed, so i was thinking that if the submitted comment is printed that may help. Is my question clear now?
private void Insert(int lblcomid, string username, string name, string comment, string tableName)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "INSERT INTO " + tableName + " (CommentID,Email,UserName,Comments) VALUES (@CommentID,@Email,@UserName,@Comments)";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
cmd.Parameters.AddWithValue("@CommentID", lblcomid);
cmd.Parameters.AddWithValue("@Email", HttpContext.Current.User.Identity.Name);
cmd.Parameters.AddWithValue("@UserName", name);
cmd.Parameters.AddWithValue("@Comments", comment);
// cmd.Parameters.AddWithValue("@FImageName", imagename);
con.Open();
//
cmd.ExecuteNonQuery();
con.Close();
}
this.BindDataList();
}
}
<asp:DataList ID="GETCOMENT1" runat="server" OnItemDataBound="GETSHARECOMENT_ItemDataBound">
<ItemTemplate>
<asp:Label ID="Label124" runat="server" Text='<%#Eval("Comments") %>' Font-Bold="False"
ForeColor="#333333" />
<asp:DataList ID="DataListCOOMENT2" runat="server">
<ItemTemplate>
<asp:TextBox ID="txtcommentpost" runat="server" Rows="1" cols="20" CssClass="txtbox form-control"
placeholder="Reply..." OnTextChanged="OnTextChanged" MaxLength="500" TextMode="MultiLine"
BorderStyle="Solid" BorderWidth="1"></asp:TextBox>
<asp:LinkButton ID="LinkButton2" runat="server" CssClass=" btn btn-sm" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px">Post</asp:LinkButton><
<asp:Label ID="Label124" runat="server" Text='<%#Eval("Comments") %>' Font-Bold="False"
ForeColor="#333333" />
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>