获取gridview中Check_changed事件的列的值。

时间:2022-05-24 09:42:00

I have a grid view which contains date and time string in dataBound field and check box in item template field. Now when user check any check box, i want to make isChecked field of my data table(Which is data source for gridview and isCheck is added programatically) true/false accourdingly. How can I get date time string from gridview based on the check box checked/uncheked??

我有一个网格视图,它在dataBound字段中包含日期和时间字符串,在item模板字段中包含复选框。现在,当用户选中任何复选框时,我想要使我的数据表的isChecked字段(它是gridview的数据源,isCheck是编程添加的)正确/错误。如何根据勾选/未勾选的复选框从gridview获取日期时间字符串?

1 个解决方案

#1


2  

You can do like...

你可以像…

<asp:TemplateField HeaderText="Date">
    <ItemTemplate>
      <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
     <asp:TemplateField HeaderText="Checkbox">
        <ItemTemplate>
           <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" 
                    oncheckedchanged="CheckBox1_CheckedChanged" />
         </ItemTemplate>
</asp:TemplateField>

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
   String Date = ((Label)((CheckBox)sender).Parent.FindControl("lblDate")).Text;
}

#1


2  

You can do like...

你可以像…

<asp:TemplateField HeaderText="Date">
    <ItemTemplate>
      <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
     <asp:TemplateField HeaderText="Checkbox">
        <ItemTemplate>
           <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" 
                    oncheckedchanged="CheckBox1_CheckedChanged" />
         </ItemTemplate>
</asp:TemplateField>

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
   String Date = ((Label)((CheckBox)sender).Parent.FindControl("lblDate")).Text;
}