I am trying to make update row database using repeater but i Fail on itemcommand event is not working
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" OnItemDataBound="Repeater1_ItemDataBound" ><ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("rom_id") %>'></asp:Label>
<table style="margin-left:20px; margin-top:20px; width:100%;">
<tr><td class="admin_add_td">Category:</td><td>
<asp:DropDownList ID="category_ddl" CssClass="admin_txtbox" runat="server">
<asp:ListItem>Stock Rom</asp:ListItem>
<asp:ListItem>Custom Rom</asp:ListItem>
</asp:DropDownList></td></tr>
<tr><td class="admin_add_td">Rom Title</td><td>
<asp:TextBox ID="admin_txtbox_title" CssClass="admin_txtbox" Text='<%# Eval("rom_title") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Brand Name</td><td>
<asp:DropDownList ID="brand_ddl" CssClass="admin_txtbox" runat="server">
<asp:ListItem>--Select Brand--</asp:ListItem>
<asp:ListItem>Micromax</asp:ListItem>
<asp:ListItem>Huawei</asp:ListItem>
<asp:ListItem>Karbonn</asp:ListItem>
<asp:ListItem>Xolo</asp:ListItem>
<asp:ListItem>Spice</asp:ListItem>
<asp:ListItem>Vivo</asp:ListItem>
<asp:ListItem>Xiaomi</asp:ListItem>
<asp:ListItem>Lenovo</asp:ListItem>
<asp:ListItem>OPPO</asp:ListItem>
<asp:ListItem>Samsung</asp:ListItem>
<asp:ListItem>HTC</asp:ListItem>
<asp:ListItem>ZTE</asp:ListItem>
<asp:ListItem>LG</asp:ListItem>
<asp:ListItem>Coolpad</asp:ListItem>
<asp:ListItem>Elephone</asp:ListItem>
<asp:ListItem>Haier</asp:ListItem>
<asp:ListItem>Gionee</asp:ListItem>
<asp:ListItem>Acer</asp:ListItem>
<asp:ListItem>ASUS</asp:ListItem>
<asp:ListItem>Motorola</asp:ListItem>
<asp:ListItem>Intex</asp:ListItem>
<asp:ListItem>Celkon</asp:ListItem>
<asp:ListItem>iBall</asp:ListItem>
<asp:ListItem>Lava</asp:ListItem>
<asp:ListItem>Panasonic</asp:ListItem>
<asp:ListItem>Others</asp:ListItem>
</asp:DropDownList></td></tr>
<tr><td class="admin_add_td">Model Name</td><td>
<asp:TextBox ID="admin_txtbox_model_name" CssClass="admin_txtbox" Text='<%# Eval("model_name") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Model no.</td><td>
<asp:TextBox ID="admin_txtbox_model_no" CssClass="admin_txtbox" Text='<%# Eval("model_no") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Rom Name</td><td>
<asp:TextBox ID="admin_txtbox_rom_name" CssClass="admin_txtbox" Text='<%# Eval("rom_name") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Rom Version</td><td>
<asp:TextBox ID="admin_txtbox_rom_version" CssClass="admin_txtbox" Text='<%# Eval("rom_version") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Credit:</td><td>
<asp:TextBox ID="admin_txtbox_made_by" TextMode="MultiLine" CssClass="admin_txtbox_multiline" Text='<%# Eval("rom_made_by") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Rom Description</td><td>
<asp:TextBox ID="admin_txtbox_rom_feature" CssClass="admin_txtbox_multiline" TextMode="MultiLine" Text='<%# Eval("rom_features") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Rom Installation</td><td>
<asp:TextBox ID="admin_txtbox_rom_installation" CssClass="admin_txtbox_multiline" TextMode="MultiLine" Text='<%# Eval("rom_install") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download Title1</td><td>
<asp:TextBox ID="admin_txtbox_download_title1" CssClass="admin_txtbox" Text='<%# Eval("download_title1") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download link1</td><td>
This is my repeater code:-
<asp:TextBox ID="admin_txtbox_download_link1" CssClass="admin_txtbox" Text='<%# Eval("download_link1") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download Title2</td><td>
<asp:TextBox ID="admin_txtbox_download_title2" CssClass="admin_txtbox" Text='<%# Eval("download_title2") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download link2</td><td>
<asp:TextBox ID="admin_txtbox_download_link2" CssClass="admin_txtbox" Text='<%# Eval("download_link2") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download Title3</td><td>
<asp:TextBox ID="admin_txtbox_download_title3" CssClass="admin_txtbox" Text='<%# Eval("download_title3") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download link3</td><td>
<asp:TextBox ID="admin_txtbox_download_link3" CssClass="admin_txtbox" Text='<%# Eval("download_link3") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download Title4</td><td>
<asp:TextBox ID="admin_txtbox_download_title4" CssClass="admin_txtbox" Text='<%# Eval("download_title4") %>' runat="server"></asp:TextBox></td></tr>
<tr><td class="admin_add_td">Download link4</td><td>
<asp:TextBox ID="admin_txtbox_download_link4" CssClass="admin_txtbox" Text='<%# Eval("download_link4") %>' runat="server"></asp:TextBox></td></tr>
<tr><td></td><td>
<%--<asp:Button ID="rom_update_btn" runat="server" Text="Rom Detail Update" OnClick="rom_update_btn_Click" /></td></tr>--%>
<asp:LinkButton ID="LinkButton1" CommandName="Edit" CommandArgument='<%# Eval("rom_id") %>' runat="server">Update</asp:LinkButton>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
</table><br />
</ItemTemplate>
</asp:Repeater>
My C# Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.IO;
public partial class adminpanel_adminpages_update : System.Web.UI.Page
{
//SqlConnection admin_con;
SqlCommand cmd;
string rom_detail_insert_con = ConfigurationManager.ConnectionStrings["rom_con"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
repeater();
}
}
public void repeater()
{
SqlConnection con = new SqlConnection(rom_detail_insert_con);
SqlCommand cmd = new SqlCommand("select * from rom_details where rom_id=" + Request.QueryString["rom_id"] + "", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet dt = new DataSet();
da.Fill(dt);
Repeater1.DataSource = dt.Tables[0];
Repeater1.DataBind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
SqlConnection con = new SqlConnection(rom_detail_insert_con);
if (e.CommandName == "Edit")
{
//string id = ((Label)e.Item.FindControl("Label1")).Text;
string id = Request.QueryString["rom_id"];
DropDownList ddlType = (DropDownList)e.Item.FindControl("category_ddl");
DropDownList brand_ddl = (DropDownList)e.Item.FindControl("brand_ddl");
string title = ((TextBox)e.Item.FindControl("admin_txtbox_title")).Text;
string model_name = ((TextBox)e.Item.FindControl("admin_txtbox_model_name")).Text;
string model_no = ((TextBox)e.Item.FindControl("admin_txtbox_model_no")).Text;
string rom_name = ((TextBox)e.Item.FindControl("admin_txtbox_rom_name")).Text;
string rom_version = ((TextBox)e.Item.FindControl("admin_txtbox_rom_version")).Text;
string credit = ((TextBox)e.Item.FindControl("admin_txtbox_made_by")).Text;
string rom_feature = ((TextBox)e.Item.FindControl("admin_txtbox_rom_feature")).Text;
string rom_install = ((TextBox)e.Item.FindControl("admin_txtbox_rom_installation")).Text;
string dt1 = ((TextBox)e.Item.FindControl("admin_txtbox_download_title1")).Text;
string dl1 = ((TextBox)e.Item.FindControl("admin_txtbox_download_link1")).Text;
string dt2 = ((TextBox)e.Item.FindControl("admin_txtbox_download_title2")).Text;
string dl2 = ((TextBox)e.Item.FindControl("admin_txtbox_download_link2")).Text;
string dt3 = ((TextBox)e.Item.FindControl("admin_txtbox_download_title3")).Text;
string dl3 = ((TextBox)e.Item.FindControl("admin_txtbox_download_link3")).Text;
string dt4 = ((TextBox)e.Item.FindControl("admin_txtbox_download_title4")).Text;
string dl4 = ((TextBox)e.Item.FindControl("admin_txtbox_download_link4")).Text;
string update_query = "update rom_details set "+
"category=@category,"+
"rom_title=@rom_title,"+
"brand_name=@brand_name,"+
"model_name=@model_name,"+
"model_no=@model_no,"+
"rom_name=@rom_name,"+
"rom_version=@rom_version,"+
"rom_made_by=@rom_made_by,"+
"rom_features=@rom_features,"+
"rom_install=@rom_installation,"+
"download_title1=@download_title1,"+
"download_link1=@download_link1,"+
"download_title2=@download_title2,"+
"download_link2=@download_link2,"+
"download_title3=@download_title3,"+
"download_link3=@download_link3,"+
"download_title4=@download_title4,"+
"download_link4=@download_link4 "+
"where rom_id=@Id";
cmd = new SqlCommand(update_query, con);
cmd.Parameters.AddWithValue("@category", ddlType);
cmd.Parameters.AddWithValue("@rom_title", title);
cmd.Parameters.AddWithValue("@brand_name", brand_ddl);
cmd.Parameters.AddWithValue("@model_name", model_name);
cmd.Parameters.AddWithValue("@model_no", model_no);
cmd.Parameters.AddWithValue("@rom_name", rom_name);
cmd.Parameters.AddWithValue("@rom_version", rom_version);
cmd.Parameters.AddWithValue("@rom_made_by", credit);
cmd.Parameters.AddWithValue("@rom_features", rom_feature);
cmd.Parameters.AddWithValue("@rom_installation", rom_install);
cmd.Parameters.AddWithValue("@download_title1", dt1);
cmd.Parameters.AddWithValue("@download_link1", dl1);
cmd.Parameters.AddWithValue("@download_title2", dt2);
cmd.Parameters.AddWithValue("@download_link2", dl2);
cmd.Parameters.AddWithValue("@download_title3", dt3);
cmd.Parameters.AddWithValue("@download_link3", dl3);
cmd.Parameters.AddWithValue("@download_title4", dt4);
cmd.Parameters.AddWithValue("@download_link4", dl4);
cmd.Parameters.AddWithValue("@Id", e.CommandArgument);
//admin_con.Open();
//cmd.ExecuteNonQuery();
//admin_con.Close();
//SqlDataAdapter da = new SqlDataAdapter(adp);
//DataTable dt = new DataTable();
//da.Fill(dt);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
repeater();
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DropDownList ddlType = (DropDownList)e.Item.FindControl("category_ddl");
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
SqlConnection con = new SqlConnection(rom_detail_insert_con);
SqlCommand cmd = new SqlCommand("select * from rom_details where rom_id=" + Request.QueryString["rom_id"] + "", con);
SqlDataAdapter SqlAd1 = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlAd1.Fill(dt);
ddlType.DataTextField = "category";
ddlType.DataSource = dt;
ddlType.DataBind();
ddlType.SelectedValue = DataBinder.Eval(e.Item.DataItem, "category").ToString();
}
DropDownList brand_ddl = (DropDownList)e.Item.FindControl("brand_ddl");
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
SqlConnection con = new SqlConnection(rom_detail_insert_con);
SqlCommand cmd = new SqlCommand("select * from rom_details where rom_id=" + Request.QueryString["rom_id"] + "", con);
SqlDataAdapter SqlAd1 = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlAd1.Fill(dt);
brand_ddl.DataTextField = "brand_name";
brand_ddl.DataSource = dt;
brand_ddl.DataBind();
brand_ddl.SelectedValue = DataBinder.Eval(e.Item.DataItem, "brand_name").ToString();
}
}
}