Footertemplate in gridview - asp.net

I am using datatable to fill gridview.
How can i add blank row in datatable to view footertemplate even if i don't have any data ?
I am using asp.net 2005. I am using gridview control to add,edit and modify the data. i put add control at footertemplate. it's working fine but i face one problem that when ever there is no data in the grid then footertemplate is not visible. I want footertemplate will be visible all the time so that user can add data even though there is no data available.
Can any body help me out...
Thanks

I ran into this as well. If I remember correctly, there is no way to actually fix it. I worked around the issue by creating an empty data template that had the controls I needed to be able to add the data.

There are a couple tricks to doing this, and most of them are kind of "ad hoc". The route I took was to intercept my datasource and check the row count. If the row count was 0, then I went ahead and injected my own row into the dataset with a coded "blank" value. Then in the databinding event, I made sure that the empty row just put empty strings into the proper fields, allowing the footer to still render.
The other route to go would be to essentially subclass the GridView class and add a few extensions so that you can still display the header/footer when there is no data. Matt Berseth has a nice little article on how to accomplish this.

Related

ASP.NET three-level databinding

I have custom objects I am binding to using ObjectDataSource. I have three-level binding: a DropDownList (Department) that filters the next DropDownList (Category) that filters a GridView (Questions). Each ObjectDataSource binds to the previous control's SelectedValue (except the first one, of course).
Everything works fine only to the next level (Department to Category and Category to Questions). When I change the Department, the Category list gets updated correctly, but the Questions that show up are from the previously selected category.
How can I get this three-level binding to work correctly? I can't figure out whether I am missing something. If I have to, I could implement SelectedIndexChanged on the first list and manually force the update on the grid, but this is not ideal. Thanks for your help!
A bit more info: I don't have a default "select an item" option. That means that when I change the Department, the first Category is automatically selected. I was hoping the binding would be smart enough to trickle that all the way down. It was smart enough that I didn't have to do the if (!IsPostBack) { // Load data }.
I currently have implemented Department_SelectedIndexChanged() and simply done a Questions.DataSource = Questions.DataSource;. That seems to "refresh" everything properly. Is there a better way to do this?
Could you clear the grid instead until the second value is refreshed? Are you looking for an AjAX appraoch, or does this use postbacks?
There isn't an automatic solution that I'm aware of so you would need to do something like you mentioned because how else would the page know to refresh the grid?

ASP.net - Adding a control in code, how do I get it via FindControl()?

I create a table in code, add rows and then cells to it. In each cell there is a checkbox which has an ID I set.
I add this table to an updatepanel, and later on I want to find out which checkboxes the user has checked/unchecked.
I don't know the best way, so what I did was create a button that checks. I kept a reference to the checkboxes, and tried changing the checkedvalue in code, but this did not update my webpage. I figure it loses the reference once it is added in code.
So I tried to use Page.FindControl and passed the original ID I gave it, but it doesn't find it. I am guessing this is because it puts a load of crap before the ID before adding it to the page...
So basically, what do I do to check the if the checkboxes I added have been altered or not? A CheckedChange event didn't work either.
You may have to use a recursive FindControl

Can database fields be dragged and dropped (as textboxes, not a gridview) into an ASP.Net form?

In VisualStudio, when you drag and drop a table or an individual column from a data connection in server explorer, a gridview is created.
What I want to be able to do is drag and drop the columns to make a quick and dirty detail form to display an individual record. Is this possible in any way?
An even better way to do this would be via a custom T4 or LLBLGen template but I have no clue how to do this.
Any other suggested approaches?
UPDATE: A DetailsView is the type of thing I am looking for, in that you can select a data source and the specific columns you want, but I'd like to be able to have manual control of the layout and formatting after the initial drag and drop.
I suggest binding a DetailsView to the table using a data source (SqlDataSource) instead. You might find these tutorials, especially this one helpful.
In response to your update, have a look at the FormView control. It gives you complete control of the layout using templated sections.
There appears to be literally no way to do this in VS that I have come across.

Can I move the automatically generated Edit and Delete columns ASP.Net to the end of the table?

I am using ASP.Net 2.0. I am using a gridview component over some data because I wanted to get the paging functionality it provides. The rest of my site where I do not need to provide paging because I have used an alphabetical index or because the result set is small enough to fit in the screen I use a repeater. In the repeater I have added the delete shortcut to the end of the table in its own cell. The edit link is provided by clicking on any row in the results and that takes you to a new screen where you can edit the details.
I have not been able to find a way to move the edit and delete columns to the end. Is there perhaps a property that I missed or is the easiest way of doing this going to be extending the Gridview component. If that is the case would it better to extend the component or try and write my own paging functionality to acompany my repeater.
Rather than using the autogenerate delete and edit buttons, you can manually add an edit and delete field using the 'Edit Columns' dialogue from the gridView smart tag. Make sure that Auto Generate fields is not selected and you can then add your columns as desired, and edit, delete and insert are all available as children of the CommandField option.
The best solution of them all would be to get the paging capablilities into your data access solution, so that if you need page 3 you only get those ten records and not the entire list. That way you could also use a repeater to render the list, without having to extend it with paging capabilities - just add another repeater at the bottom that loops out the page numbers as links.
However, if this is not possible, the easiest way would probably be to manually configure the GridView to render the way you want it to (or as close as possible...). It's been a while since I worked with a GridView, but the names I show below are at least close enough for you to find the correct ones with Intellisense in VS.
First, set
AutoGenerateColumns = False
on your GridView. Then, add a <Columns></Columns> section betweeen the <asp:GridView></asp:GridView> tags. Within that section, you should be able to specify each field you want to render, and the order you want them in.

ASP.net 2.0 Gridview with Expanding Panel Rows -- How to build Panel "on the fly"

I'm currently building a Gridview that has expandable rows. Each row contains a dynamically created Panel of Form elements. Right now, I have a javascript function that expands (or in my case, makes visible) the panel when an Image is clicked on the Gridview row.
My question is... is there a more efficient way of doing this. Instead of pulling all my data to begin with and building each new row as I Databind, is there a way to simple create the row with the Panel full of textboxes and dropdownlists on the fly when the user clicks the Expand button?"
I'd like to limit the server calls by doing it that way instead of how I'm currently doing it, looping through every row and creating a new panel with form elements and inserting that into a row that is hidden.
Actually, it isn't performing badly since my original SQL query can populate every single row and I have enabled paging on the Gridview. I'm just wondering if they can be built on the fly using PageMethods or some sort of JSON/AJAX solution. I haven't seen anything, but... worth a try in searching for it.
you can override the RowdataBound event, and than add whatever controls you want based on what data goes in the cell.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
Personally trying to create the data on the fly would most likely result in a slower user experience.
When I do things like what you are describing I typically use Repeaters, that way I can do a template layout that simply defines all of the needed elements right away, and it handles the binding actions.
Otherwise, I would imagine that your way isn't performing too slowly as it is.
Actually worked this recently into an AJAX Handler returning the form structure. It's on demand, and works well. Simply call $ajax via jQuery, return an HTML structure, inject into DIV. It's a bit limiting on actual functionality, so be careful.

Resources