So, I have a repeater that prints out category names from database, each of those category names have under it TextBox
and button, so that I could edit its name If I would like to, but... yeah, there is always one but. I simple can't reach the TextBox
which is repeated, it tells me that TextBox_Update
does not exist in current context.
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = @"UPDATE [categories] SET [category_name] = @category_name WHERE [category_id] = @category_id";
cmd.Parameters.AddWithValue("@category_name", TextBox1.Text);
cmd.Parameters.AddWithValue("@category_id", Request["id"]);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
Response.Redirect("default.aspx");
}
This is the way I tried to update it but... tells me that textbox
does not exist at all.
Here is how it looks like in html
<asp:Repeater ID="Repeater_Categories" runat="server" >
<HeaderTemplate>
<div class="insertPost">
<h1>Categories</h1>
<hr />
</HeaderTemplate>
<ItemTemplate>
<div class="category">
<h3><%# Eval("category_name") %></h3>
<div class="categoryEdit">
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="3"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" ValidationGroup="3" />
<a href="?action=delete&id=<%# Eval("category_id") %>">Del</a>
<br />
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
Probably doing something terribly wrong, I'm desperated for help ;<
@Edit
Fixed TextBox names..