Hey guys! I have a slight problem here,I have data grid and I have two radio buttons in the datagrid i.e approve or reject and also one button in datagrid i.e submit ,so what i want to do is when approved button is selected and submit button in the datagrid is clicked for one row I want the data of that row to be stored in the database with Isactive as 1 and the row should be deleted from the datagrid..but details must be stored in the database.Similarly when the reject button is selected and submit button in datagrid is clicked,the data of that row should be stored in the database with Isactive as 0 and the row should be deleted from the datagrid..but details must be stored in the database.How do I do this in c#..I really have got no clue..It would be great if someone could help me out.:)
The following is my ASP.NET code
<pre lang="HTML">
<asp:DataGrid ID="dgrdview" runat="server" AllowPaging="True"
CssClass="vutblrow" TabIndex="6"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" PagerStyle-Mode="NumericPages" DataSourceID="SqlDataSource1" >
<PagerStyle CssClass="pgr" Mode="NumericPages" Height="25px" BorderStyle="Solid" NextPageText="Next" PageButtonCount="20" PrevPageText="Last" />
<AlternatingItemStyle CssClass="vutblaltrow" />
<HeaderStyle CssClass="vutblhdr" />
<ItemStyle CssClass="vutblitemrow" />
<Columns>
<asp:BoundColumn HeaderText="Reference Number" DataField="empid" ItemStyle-CssClass="ing-padding_Right" HeaderStyle-BorderColor="#718bad" ItemStyle-VerticalAlign="Top">
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Employee Name" DataField="emp_name" ItemStyle-CssClass="ing-padding_Right" HeaderStyle-BorderColor="#718bad" ItemStyle-VerticalAlign="Top">
</asp:BoundColumn>
<asp:BoundColumn HeaderText="Designation" DataField="Designation" ItemStyle-CssClass="ing-padding_Right" HeaderStyle-BorderColor="#718bad" ItemStyle-VerticalAlign="Top">
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Approve">
<ItemTemplate>
<asp:RadioButton runat="server" ID="rbtnapprove" GroupName="action" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Reject">
<ItemTemplate>
<asp:RadioButton runat="server" ID="rbtnreject" GroupName="action" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Sumbit">
<ItemTemplate>
<asp:Button runat="server" ID="btnsub" CssClass="btnBack-Cancel" Text="submit" OnClick="submit" CommandName="approve" />
</asp:ButtonColumn>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DEVConnectionString %>"
SelectCommand="SELECT [empid], [emp_name], [Designation] FROM [T_TADA_temp] Where ([ID]=@ID)">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
This is my C# code that I tried,
IsActive is not getting updated in the database??...can some one tell me whats wrong?
protected void submit(object sender, EventArgs e)
{
// *Get the Gridview Row* //
DataGridItem drow = (DataGridItem)(sender as Control).Parent.Parent;
RadioButton rbpApprove = (RadioButton)drow.FindControl("rbtnapprove");
RadioButton rbpReject = (RadioButton)drow.FindControl("rbtnreject");
if (rbpApprove.Checked == true)
{
conn.Open();
SqlCommand cmd = new SqlCommand("Update table set IsActive= 0 where ARGID=@ARGID", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
else if (rbpReject.Checked == true)
{
conn.Open();
SqlCommand cmd = new SqlCommand("Update table set IsActive= 1 where ARGID=@ARGID", conn);
cmd.ExecuteNonQuery();
conn.Close();
}
string empid = dgi.Cells[0].Text;
string employeename = dgi.Cells[2].Text;
string designation = dgi.Cells[3].Text;
conn.Open();
SqlCommand comm = new SqlCommand("insert into [T_TADA_aaprovereject_groupdirector] values (" + empid + ",'" + employeename + "','" + designation + "')", conn);
comm.ExecuteNonQuery();
conn.Close();
}
}