Sunday, March 11, 2012

CalendarExtender in Datagrid

Hey,

Maybe. I say that because the textbox has ID of TextBox1 (or whatever), but when you put it in datagrid, it has to ensure a unique name, which won't be just Textbox1, but something unpredictable. However, what you could try to do is in ItemCreated or ItemDatabound events try to make the ID assignment to the calendar extender there. That might work...


Hi,

the following example is working in my case:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="CalendarInDatagrid.aspx.cs" Inherits="Calendar_CalendarInDatagrid" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %><script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { int[] dsource = new int[5]; DataGrid1.DataSource = dsource; DataGrid1.DataBind(); } }</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="TheScriptManager" runat="server"></asp:ScriptManager> <asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateColumn HeaderText="Date"> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Cal" OnClientClick="return false;" /> <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1" PopupButtonID="Button1" /> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> </form></body></html>


Thanks Garbin.

That is pretty much what I had but it did not work. I'll try again, maybe it has to do with something else on my page.

No comments:

Post a Comment