Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
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();
}
}
Posted
Updated 23-Sep-13 5:27am
v2
Comments
[no name] 23-Sep-13 11:37am    
The exception that your SQL would produce would tell you exactly what the problem is. You have not defined a parameter "@ARGID".
Member 10066916 23-Sep-13 11:42am    
yes thats the thing...I dont know how to define it...through datagrid view...i find it very confusing...

1 solution

C#
Protected void Submit(object sender, EventArgs e)
{

// *Get the Gridview Row* //
GridViewRow grow=(GridViewRow)(sender as control).Parent.Parent;

RadioButton rbpApprove=(RadioButton)grow.FindControl("rbtnapprove");

RadioButton rbpReject=(RadioButton)grow.FindControl("rbtnreject");

// *By using this method you will get the radio buttons* //
// *Use your own logic to save the details* //
}
 
Share this answer
 
Comments
Member 10066916 19-Sep-13 9:01am    
ok ill try this out ...thank you so much :)
Member 10066916 23-Sep-13 9:27am    
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();
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900