Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASP.NETGridView中使用单选按钮_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何在ASP.NETGridView中使用单选按钮

C# 如何在ASP.NETGridView中使用单选按钮,c#,asp.net,gridview,C#,Asp.net,Gridview,我想用单选按钮在Gridview中显示运行项目的当前日期。我不知道最好的方法是使用JavaScript还是C#(我在代码隐藏中使用它)以及如何做到这一点。如果需要显示一些代码,请说出来。网格中填充了一条sql语句。下图显示了我希望网格的方式。多谢各位 很遗憾,您不能在GridView中使用属性 最简单的方法是将RadioButton放置在模板字段中,并使用jQuery对其进行操作 ASPX 功能myRadioButtonClick(发送方){ $('.myRadioButton input'

我想用单选按钮在Gridview中显示运行项目的当前日期。我不知道最好的方法是使用JavaScript还是C#(我在代码隐藏中使用它)以及如何做到这一点。如果需要显示一些代码,请说出来。网格中填充了一条sql语句。下图显示了我希望网格的方式。多谢各位


很遗憾,您不能在GridView中使用属性

最简单的方法是将RadioButton放置在模板字段中,并使用jQuery对其进行操作

ASPX

功能myRadioButtonClick(发送方){
$('.myRadioButton input').attr('checked',false);
$(发送方).attr('checked',true);
}
代码隐藏
公共类客户
{
公共int Id{get;set;}
公共字符串名称{get;set;}
}
受保护的无效页面加载(对象发送方、事件参数e)
{
GridView1.DataSource=新列表
{
新客户{Id=1,Name=“John”},
新客户{Id=2,Name=“mary”},
};
GridView1.DataBind();
}

我成功了,但另一方面,我想用我的代码更新我的问题,但它说我的问题主要是代码,@MaraPimentel我很高兴你能理解。如果您以其他方式解决问题,请不要更新您的问题;相反,把你的答案贴在这里。
<asp:GridView runat="server" ID="GridView1">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:RadioButton runat="server" ID="MyRadioButton"
                    CssClass="myRadioButton"
                    onclick='<%# "myRadioButtonClick(this)" %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<script type="text/JavaScript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    function myRadioButtonClick(sender) {
        $('.myRadioButton input').attr('checked', false);
        $(sender).attr('checked', true);
    }
</script>
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
    GridView1.DataSource = new List<Customer>
    {
        new Customer {Id = 1, Name = "John"},
        new Customer {Id = 2, Name = "Marry"},
    };
    GridView1.DataBind();
}