简体   繁体   English

访问asp.net gridview编辑控件

[英]Access asp.net gridview edit control

I would like to access a calendar control through c# for when a gridview row is edited. 我想在编辑gridview行时通过c#访问日历控件。 However, I am unsure of how to access this through C# behind. 但是,我不确定如何通过后面的C#访问它。

I would like to do the following: 我要执行以下操作:

cal_SelectionChanged(object sender, EventArgs e)
{
date = cal.SelectedDate

blah blah...
}

However, as the control is in the gridview edit template, I cannot find a way to access this to C#, compared to if the calendar was just an element on a normal asp.net page. 但是,由于控件位于gridview编辑模板中,因此,与日历只是普通asp.net页上的元素相比,我无法找到将其访问C#的方法。

Thanks 谢谢

As you appear to be aware, controls within Template based controls (such as <asp:Repeaters> ) cannot be accessed directly as you would a control placed directly into a page / usercontrol / masterpage. 如您所知,基于Template的控件中的控件(例如<asp:Repeaters> )不能像直接放置在页面/用户控件/母版页中的控件那样直接访问。 It is possible to find it using the "FindControl" on the specific item within the control, but there should be an easier way... 可以使用控件中特定项目上的“ FindControl”找到它,但是应该有一种更简单的方法...

In this case you should be able to set a SelectionChanged event handler on the calendar control to the function in your code-behind. 在这种情况下,您应该能够将日历控件上的SelectionChanged事件处理程序设置为隐藏代码中的函数。 (This is assuming you're using the inbuilt Calendar control ) Something like... (这是假设您正在使用内置的Calendar控件 )类似...

<asp:Calendar runat="server" OnSelectionChanged="cal_SelectionChanged"> ... </asp:Calendar>

When an event such as this is called, the object that caused the event (in this case the calendar control) is passed into the function through the sender parameter. 调用此类事件时,导致该事件的对象(在本例中为日历控件)通过sender参数传递到函数中。

This means that instead of trying to work out which calendar was clicked, you simply can do this... 这意味着您不必尝试计算单击哪个日历,而只需执行此操作...

cal_SelectionChanged(object sender, EventArgs e)
{
  Calendar cal = (Calendar)sender;
  date = cal.SelectedDate;
  blah blah...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM