Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 25, 2010 03:56 AM by Ming Xu - MSFT
Member
14 Points
125 Posts
Aug 20, 2010 10:12 AM|LINK
hi...
i've created a form with a formview and i've connected to the database programatically
i've inserted the checkbox,label in itemtemplete..
now what i want is when i click the delete button a label should be activated indicating that
click the checkbox and then delete button..
when checkbox is checked and when i press the delete button it should delete the row..
can u provide me a code for this type of question.......?
Participant
1288 Points
305 Posts
Aug 20, 2010 11:46 AM|LINK
Write the Row Command
DeleteFunction(e.commandArgument)
All-Star
25269 Points
2235 Posts
Microsoft
Aug 25, 2010 03:56 AM|LINK
vinayak.v now what i want is when i click the delete button a label should be activated indicating that click the checkbox and then delete button.. when checkbox is checked and when i press the delete button it should delete the row..
Hi,
According to your description ,I think you can do as below.Here is a sample.
1.Code in .aspx:
<form id="form1" runat="server"> <div> <asp:FormView ID="FormView1" runat="server" AllowPaging="True" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="6" DataKeyNames="ID" GridLines="Both" Width="100%" OnPageIndexChanging="FormView1_PageIndexChanging"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> ID: <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' /> title: <asp:Label ID="TITLELabel" runat="server" Text='<%# Bind("TITLE") %>' /><br /> </ItemTemplate> <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" /> <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" /> <EditRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /> </asp:FormView> <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Delete" /> </div> </form>
2.Code in .cs:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind(); } } public void Bind() { this.FormView1.DataSource = Get_source(); this.FormView1.DataBind(); } public DataTable Get_source() { DataTable dt = new DataTable(); DataRow dr; string XM = "hello,hi,How are you,MingXu"; string XMM = "1,2,3,4"; string[] list1 = XM.Split(','); string[] list2 = XMM.Split(','); dt.Columns.Add(new DataColumn("TITLE")); dt.Columns.Add(new DataColumn("ID")); for (int i = 0; i < list1.Length; i++) { dr = dt.NewRow(); dr["TITLE"] = list1[i]; dr["ID"] = list2[i]; dt.Rows.Add(dr); } return dt; } protected void Button2_Click(object sender, EventArgs e) { CheckBox chk = this.FormView1.FindControl("CheckBox1") as CheckBox; if (!chk.Checked) { this.Label1.Visible = true; this.Label1.Text = "click the checkbox and then delete button"; } else { this.Label1.Visible = false; //Delete the row from DB and rebind the formview } }
Hope it can help you.
vinayak.v
Member
14 Points
125 Posts
checkbox in formview
Aug 20, 2010 10:12 AM|LINK
hi...
i've created a form with a formview and i've connected to the database programatically
i've inserted the checkbox,label in itemtemplete..
now what i want is when i click the delete button a label should be activated indicating that
click the checkbox and then delete button..
when checkbox is checked and when i press the delete button it should delete the row..
can u provide me a code for this type of question.......?
abdulwakeel
Participant
1288 Points
305 Posts
Re: checkbox in formview
Aug 20, 2010 11:46 AM|LINK
Write the Row Command
of the FormView and Insert The Following CodeIf e.commandName = "Delete" Then
Dim chk As CheckBox = CType(FormView1.FindControl("chkDelete"), CheckBox)If chk.Checked ThenDeleteFunction(e.commandArgument)
End If
End IfMing Xu - MS...
All-Star
25269 Points
2235 Posts
Microsoft
Re: checkbox in formview
Aug 25, 2010 03:56 AM|LINK
Hi,
According to your description ,I think you can do as below.Here is a sample.
1.Code in .aspx:
<form id="form1" runat="server"> <div> <asp:FormView ID="FormView1" runat="server" AllowPaging="True" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="6" DataKeyNames="ID" GridLines="Both" Width="100%" OnPageIndexChanging="FormView1_PageIndexChanging"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> ID: <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' /> title: <asp:Label ID="TITLELabel" runat="server" Text='<%# Bind("TITLE") %>' /><br /> </ItemTemplate> <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" /> <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" /> <EditRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /> </asp:FormView> <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Delete" /> </div> </form>2.Code in .cs:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind(); } } public void Bind() { this.FormView1.DataSource = Get_source(); this.FormView1.DataBind(); } public DataTable Get_source() { DataTable dt = new DataTable(); DataRow dr; string XM = "hello,hi,How are you,MingXu"; string XMM = "1,2,3,4"; string[] list1 = XM.Split(','); string[] list2 = XMM.Split(','); dt.Columns.Add(new DataColumn("TITLE")); dt.Columns.Add(new DataColumn("ID")); for (int i = 0; i < list1.Length; i++) { dr = dt.NewRow(); dr["TITLE"] = list1[i]; dr["ID"] = list2[i]; dt.Rows.Add(dr); } return dt; } protected void Button2_Click(object sender, EventArgs e) { CheckBox chk = this.FormView1.FindControl("CheckBox1") as CheckBox; if (!chk.Checked) { this.Label1.Visible = true; this.Label1.Text = "click the checkbox and then delete button"; } else { this.Label1.Visible = false; //Delete the row from DB and rebind the formview } }Hope it can help you.
Feedback to us
Develop and promote your apps in Windows Store