Solved

How to add ajax calendar in gridview dynamically

Posted on 2013-12-16
2
1,477 Views
Last Modified: 2013-12-17
Hi there,

in my gridview i have some textboxes in each row.

on row data bound  I want to display an ajaax calendar with the textbox if the a template field contains the value date.

for example
if (isDate == "Date")
            {
               
                AjaxControlToolkit.CalendarExtender CalBolton = new AjaxControlToolkit.CalendarExtender();
                CalBolton.ID = "calBolton" + i;
                CalBolton.Format = "dd/MM/yyyy";
                CalBolton.TargetControlID = txtBoltonCCG.ID;
                grdStandsrds.Controls.Add(CalBolton);
                i = i + 1;
            }

kind regards,
0
Comment
Question by:shah36
2 Comments
 
LVL 19

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
Comment Utility
It's not completely clear what your question is. However, I will do what I can to answer this the best I can.

First off, you are going to do this in the GridView RowDataBound event, right?

Secondly, you are going to work with RowData such that in the event, e:

e.Row.RowType == DataControlRowType.DataRow, right?

Third, you are going to grab the the cells in this fashion:

TableCell myCell = e.Row.Cells[0];

Each cell will be indexed 0...whatever being the number of columns you have in the row. Therefore, Column 0 would be e.Row.Cells[0] and Column 1 would be e.Row.Cells[1], etc.

You'd need to find the column for your calendar: e.Rows.Cells9x] where x is the column for the textbox with the date in it.

Then, you'd build your calendar control, like you already are doing. Then, you's simply add it to the column:

e.Row.Cells[x].Controls.Add(myCalendarControl);

Or, if you do like I do, first:

TableCell startDateCell = e.Row.Cells[x];
startDateCell.Controls.Add(myCalendarControl);

works too.

You do this within the RowDataBound event for each and every column.
0
 

Author Closing Comment

by:shah36
Comment Utility
Thank you so much. It worked like a charm.

regards,
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now