如何确定哪个单选按钮在网格视图行中对amomg 4 radiobutton进行了查询 [英] how to determine which radiobutton is chaked amomg 4 radiobutton in a gridview row

查看:135
本文介绍了如何确定哪个单选按钮在网格视图行中对amomg 4 radiobutton进行了查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网格,并且每行有4个radiobutton.i最初设置了第一行的第一个收音机被检查=真,其余3假。

现在问题是我无法确定在代码中,从gridview的每一行检查无线电。每次在代码中显示第一个收音机被检查。我得到错误的值



-------------- ------------------------------------



i have grid and in each row there are 4 radiobutton.i have initially set the first radio of a row is checked=true and rest 3 false.
now the problem is i can not determine in code that which radio is checked from each row of the gridview. every time in code it is showing that first radio is checked.thus i am gettin the wrong value

--------------------------------------------------

<table width="100%">
                                        <tr>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel11" runat="server">
                                                    <ContentTemplate>
                                                        <asp:GridView ID="dgvAttandance" runat="server" AutoGenerateColumns="false" DataKeyNames="StffId"

                                                            Width="100%" CssClass="style5">
                                                            <Columns>
                                                                <asp:TemplateField HeaderText="Stff Id" HeaderStyle-HorizontalAlign="Center">
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblStffId" runat="server" Text='<%# Bind("StffId")%>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="Name" HeaderStyle-HorizontalAlign="Center">
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblName" runat="server" Text='<%# Bind("Name")%>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="Date Time" HeaderStyle-HorizontalAlign="Center">
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblDT" runat="server" Text='<%# Bind("DT")%>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="Attendance">
                                                                    <ItemTemplate>
                                                                        <asp:RadioButton ID="rdoP" Text="P" ForeColor="Green" Font-Bold="true" runat="server"

                                                                            Checked="true" GroupName="Att" />
                                                                         
                                                                        <asp:RadioButton ID="rdoA" Text="A" ForeColor="Blue" Font-Bold="true" runat="server"

                                                                            Checked="false" GroupName="Att" />
                                                                         
                                                                        <asp:RadioButton ID="rdoS" Text="S" ForeColor="Red" Font-Bold="true" runat="server"

                                                                            Checked="false" GroupName="Att" />
                                                                         
                                                                        <asp:RadioButton ID="rdoH" Text="H" ForeColor="Orange" Font-Bold="true" runat="server"

                                                                            Checked="false" GroupName="Att" />
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                            </Columns>
                                                        </asp:GridView>
                                                    </ContentTemplate>
                                                </asp:UpdatePanel>
                                            </td>
                                        </tr>
                                    </table>





--------------------- ------------------



---------------------------------------

for (int index = 0; index <= dgvAttandance.Rows.Count - 1; index++)
           {
               char stat = new char();
               RadioButton P = (RadioButton)dgvAttandance.Rows[index].FindControl("rdoP");
               RadioButton A = (RadioButton)dgvAttandance.Rows[index].FindControl("rdoA");
               RadioButton S = (RadioButton)dgvAttandance.Rows[index].FindControl("rdoS");
               RadioButton H = (RadioButton)dgvAttandance.Rows[index].FindControl("rdoH");
               if (P.Checked)
               {
                   stat = Convert.ToChar("P");
               }
               else if (A.Checked)
               {
                   stat = Convert.ToChar("A");
               }
               else if (S.Checked)
               {
                   stat = Convert.ToChar("S");
               }
               else if (H.Checked)
               {
                   stat = Convert.ToChar("H");
               }

               DT.Rows.Add(((Label)dgvAttandance.Rows[index].FindControl("lblStffId")).Text, ((Label)dgvAttandance.Rows[index].FindControl("lblName")).Text, stat);
           }

推荐答案

这篇关于如何确定哪个单选按钮在网格视图行中对amomg 4 radiobutton进行了查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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