How to create and edit gridview at runtime along with adding rows? - asp.net

I have a aspx page consisting of a calendar button and a textbox.When we click calendar button then a calendar appears and the date which i select on calendar appears in textbox. Now what i want is to load the data from database according to the date selected and allow the user to edit it.And also i want to enable user to add rows at runtime. Do i need to create grid view at runtime?? Can somebody point me in a direction??

You don't need to create the gridview at runtime. You can define the gridview in the markup without having any data initially. You can set the calendar to autopostback and on the server side, capture the new date selected, grab the data based on that date and bind it to your gridview.
As far as editing the data, Gridviews already provide support for this and the amount of code that you need to write largely depends on how the datasource for the gridview is set up. If you use a SQLdatasource with the appropriate settings you practically don't have to write a single line of code besides the markup (Google: Gridview SQLdatasurce editing ASP.net).

Related

asp.net change cell value on gridview with code behind

I have an asp.net gridview with several rows/pages.
There are some fields below it which display full details of the row which has been clicked on gridview.
I then change a field value on the details below area and the new data is saved programmatically to database.
However the value on the gridview just changed below, doesn't change.
I would like to just change de cell value on the gridview programmatically so there is no need to reload the data grid.
I am basically looking for something like:
GridView1Row.row(currentrow).column(5)="xxxx"
I've search around and found some solutions based on _onrowdatabound but this is not correct, as I just want to change one cell of the grid.
Any ideas ?
The easiest way would be to change the value in your datasource and then binding the datasource to the grid again. (don't reload it from the database just change the value in the datasource)

Which control should I use to show post records from my database in ASP.NET?

Which control should I use to show post records from my database in ASP.NET?
On my project page I would like to show recently featured projects. The number of projects can vary. I'm looking for a control like GridView or something that alter the properties of accordingly to get data from my database.
Below is an image of what I would like my page to look like:
I have been told to use asp:ListView but I don't know how to use it. Is this the right solution for my problem?
You could use a GridView Class
Displays the values of a data source in a table where each column
represents a field and each row represents a record. The GridView
control enables you to select, sort, and edit these items.
Or a Repeater Class
A data-bound list control that allows custom layout by repeating a
specified template for each item displayed in the list.

GridView with a custom button

Specifically, I am using DevExpress 10.1 for their APSxGridView. I have a grid with a command column. I plan on using two of the standards: new and edit. I would like to create a custom button that will take a value from within the current row and redirect to another page using that value as part of the query string.
I have seen some suggestions to create a hyperlink column to do this, but I would like to have all of these commands in a single column. I can see solutions for this if I weren't constrained by leaving all buttons within a single column. Is this something that maybe I could assign during HtmlDataCellPrepared?
Thanks.
If it's anything like the standard .net GridView I would create a template field. In a template field you can put whatever you want in there. I have done this when I need an asp.net control (a button, hyperlink, etc) instead of the standard grid buttons and commands. You can then access controls and the datasource during the OnRowDataBound event handler and customize the button during run time if need be.

dymanically increasing number of textboxs in webforms

I have a database with 2 records Id and Description.
What I want to do is try to bind this to a table so for example
<tr>
<drop down select list with ids available> <textbox>
</tr> <add button>
So the user can select an id from the drop down list, enter a description then click an add button next to this which will duplicate that block dynamically so they can enter as many as they like. What is the best way to go about this in webforms? Detailsview? I'm not sure how to make it dynamically add html blocks though? Any help would be appreciated.
pseudocode :
foreach description
create new tablerow
create a table cell in the row with the description as a label
create a table cell in the row with the id dropdown as a combobox
add the tablerow to the table.rows collection
the tricky part is accessing the data in your dynamically created table, but it shouldn't be hard to do as long as you set an identifier on each control that can be tied back to your data.
I'd stay away from any of the built in controls (i.e. DetailsView, FormView) for anything other than simple CRUD forms, as it's not much more effort to manually create your own data-entry forms.
Dynamically adding controls to an ASP.NET Webform (and have them work across postbacks) is quite a tricky one to get right, but in short you'll need to do something like:
Add a table server control which will store your dynamic rows.
Create a property (stored in ViewState or ControlState) to store a count of rows available.
Handle the appropriate 'add' button click event, to increment the count property and add a new table row, and child controls.
Inside an OnInit event, create the number of table rows stored in the count property.
Dynamically created controls aren't persisted across postbacks, so you'll need to create them on every postback during the pages OnInit method. As long as the controls are recreated in the right order and with the same ID's, then they will be repopulated successfully on postback.
Because you're dynamically adding controls, you may need to set the pages EnableEventValidation property to false.

ASP.NET GridView - Editing Dynamic Template Columns

I have created a GridView whose columns are dynamically created based on my data source. I have implemented these columns by using the approach described here.Those columns display properly on the initial load. However, I need to implement commanding so that a user can edit / delete a row in the GridView.
At this point, I have implemented commanding as I would with a normal GridView. I have a TemplateField with an ItemTemplate that has LinkButton elements for edit and delete. The CommandName for each LinkButton is set to either Edit or Delete respectively.
Oddly, when a user clicks either the Edit or Delete link, the data in the GridView disappears. However, I have verified that I am in fact re-binding the data when one of these LinkButton elements is selected.
Can anyone provide some suggestions as to what the cause could be?
Thank you!
Here are good examples. You can figure out postback issue.
http://quickstarts.asp.net/QuickStartV20/aspnet/

Resources