Datagrid中的单选按钮 [英] Radio button in Datagrid

查看:78
本文介绍了Datagrid中的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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>





这是我试过的C#代码,



IsActive没有在数据库中更新? ......有人可以告诉我什么是错的?





protected void submit(对象发送者,EventArgs e)

{

// *获取Gridview行* //

DataGridItem drow =(DataGridItem)(发件人为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其中ARGID = @ ARGID,conn);



cmd.ExecuteNonQuery();

conn.Close();





}







else if(rbpReject.Checked == true)

{

conn.Open();

SqlCommand cmd = new SqlCommand(更新表集IsActive = 1,其中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 +','+ names +'),conn);

comm.ExecuteNonQuery();

conn.Close();

}

}



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();
}
}

推荐答案

ConnectionStrings:DEVConnectionString %>

SelectCommand = SELECT [empid],[emp_name],[名称] FROM [T_TADA_temp]其中([ID] = @ ID) >
< SelectParameters >

< asp:QueryStringParameter 名称 = ID QueryStringField = ID 类型 = 十进制 / < span class =code-keyword>>
< / SelectParameters >




< < /跨度> <温泉n class =code-leadattribute> / asp:SqlDataSource >
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>





这是我试过的C#代码,



IsActive没有在数据库中更新?? ...有人可以告诉我什么错误?





protected void submit(对象发送者,EventArgs e)

{

// *获取Gridview行* //

DataGridItem drow =(DataGridItem)(发件人为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其中ARGID = @ ARGID,conn);



cmd.ExecuteNonQuery();

conn.Close();





}







else if(rbpReject.Checked == true)

{

conn.Open();

SqlCommand cmd = new SqlCommand(更新表集IsActive = 1,其中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 +','+ names +'),conn);

comm.ExecuteNonQuery();

conn.Close();

}

}



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();
}
}


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* //
}


这篇关于Datagrid中的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆