Inserting the elements in grid column wise and creating different controls - c#

I am new to Asp.net and C#.I am working in a project where I need to create GridView.Now I wanted to bind this column wise with the data.Like the column1 in the grid is "Category" in the table of database and so on. I also want to create the Hyperlink on the basis of the content in database for example I want to show the text of Hyperlink as "This is Java program" and URL specifies as "http://blogs.article?id=1".Please tell me that how I can do that.Currently I am able to bind the all three columns in the table to the three columns in the grid.

Take a look at the HyperLinkField class. This should provide exactly what you're looking for.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx

Related

Asp.net: alternative for gridview + horizontal accordion that display a table?

I need to make a table with huge data from a database, I've done it very easy with a gridview in asp.net but there is a big problem,I need to customize that table a lot.
I want something like this, with a row with data about a person and the row after with a description of projects he's in, then another row with another person data and so on.
Table:
https://ibb.co/dJmEqw
And when i click/hover on a platform(platform i want to be a accordion propriety/it can be a button too) to display a table in the right or down side.
Table inside the platform's accordion:
Hope you get the idea guys, how can I do this with horizontal table lines, tables in accordions click/hover and databind? I need to take data from database and put it in the tables I described but I don't know if i can do that with asp.net gridviews which automatically generate the rows/columns it needs or is it another method ?
Any idea, advice, code is welcome, thanks!
A GridView is a simple "PowerPoint" solution for simple data models.
If you want more complex things get rid of the GridView and use a Repeater to create your HTML table instead. The Repeater control lets you create the table row tags in the ItemTemplate. You can easily generate two rows for each item in DataSource.
Of course, you need to generate the table cells (columns) manually as well with the Repeater control. Use Literal or Label controls to view the data in the table cells. Use
<%#: DataBinder.Eval(Container.DataItem, "propertyname") %>
to assign the Text properties of the controls.

Multiple row input in asp.net for editing database table

From time to time, I need to create an input control which allows multiple rows of input, the type of input and number of columns could be different in each case but typically it would be represent a database table being edited, so it should also be possible to store an id value within each row. It should also be possible for the user to add new rows to the input if they have more data to input.
I have tried a couple of approaches to this but they are all very long winded for what seems like such an obvious and common scenario. I'm thinking that there must be a simple way to do this that I have missed.
The way that I usually solve this is by using a list view, enter all of the input controls required within the item template and use a html table for formatting, with each item being a row of the table. If there is existing data to be edited, I would load the data from the database, add a blank object to the results and bind it to the list view. If there is no existing data, I would create a collection with a blank record in it and bind it to the list view. I add a button for adding a new row. When clicked, this button retrieves all of the existing data from the list view by iterating all of the listview items and populating the data into a collection, which I would then add a blank object to and rebind the listview with the results. When saving, I would retrieve the results by iterating the listview items again and using a hidden field within each row to store the record id. This would determine whether a new record was added or an existing record was edited.
This approach works for me but I'm sure there must be simpler ways to achieve this. Looking forward to seeing how other people solve this.
For web forms, use a GridView. You can set its properties to allow editing, deleting, new rows, sorting, and paging.
Check out the MSDN example here that shows how to use it. If you bind a datasource to it, it will figure out the columns and adjust dynamically then, or you can predefine the columns you want for more customability.
You are talking about bulk insert/update. You could use XML insertion/updation for this purpose. Get all the data to a DataSet ds variable. Then use ds.GetXml() method to convert the dataset to XML string. Pass this to an XML parameter into SQL server which has the datatype 'XML'
INSERT INTO YOURTABLE
SELECT
V.VOI.value('(.)[1]', 'int')
FROM
#Input.nodes('/DATASETNAME/DATATABLENAME/') V(VOI)
Use this link to learn more
You need dynamic table with Add, View,Edit and delete operations on each data.
I would suggest using DataTable Jquery component. there are tons of examples on Data operations, and you can plug this with any Server technology including ASP.net
http://editor.datatables.net/

Creating Tables with Multiple Headers in DataGridView in C#

I would like to create a table with multiple headers using DataGridView in C#. I can create a table. However, I need multiple headers in the table. Attached is the screenshot of the table I would like to create.
Any idea how to do it.
This is the concept regarding DataGrid with in DataGrid.You first have to Bind MasterGrid and then bind Child grids with in Master grid.This link will surely help you :
http://www.codeproject.com/Articles/22928/GridView-within-GridView`

hide columns by Id in gridview in asp.net

I have the asp.net application where I am having the editable grid view with the edit,Delete,Add options. this grid having as usual Template fields . I want to hide some columns. I know i can do that by using columns index. but i don't want to follow it. instead I want to hide columns by Id. this is because if in my application further I need to add more columns then there is need to change the code gain and again in the core. so I am choosing this way. Bu as i found <asp:TemplateField /> does not contain Id attribute. so it is become impossible for me to hide <asp:TemplateField/> by Id. any remedy for this ?
You can always do it using column header text. Run a loop through columns of the grid view and compare header text of the column with the constant declared and hide the column, this way, if you are adding any number of columns before or after the column will not affect the code.
Maybe create a div with an id inside a template field and hide that div with client code.
Perhaps just have a different grid markup for each "view" you want to show to the user, so one grid with all the columns, and another with limited columns.
I am assuming you would always be binding the same data to the grid (regardless of whether you are hiding/showing columns), so then you would just need some logic in your code to determine what "view" you want to show the user (i.e. what grid you want to bind to).

Adding rows to a table based on user input (ASP.NEt)

I have a TextBox entry field where the user will enter a integer value. And then there is a "Create" button, which when clicked upon must generate a Table with 2 columns :
"Name" and "Email" being the column headers.
I want each row to have a textbox in each of these columns.
All of this has to happen after the button is clicked. I have discovered that if you dynamically add a control in ASP.NET(I am using C#) then the controls are lost during postback. And I don't know how to prevent that from happening.
Can somebody please give me some ideas regarding how to go about adding rows dynamically to a table (I tried using the asp.net Server side table control but ran into the "lost-during-postback" problem - can I try with something else like a gridview ? but afaik a GV will not work without data bound to it )
Point to note is that my table has textboxes for user entry and it is not for showing data ..rather it is for accepting data from the user which will be later used to persist details to the database.
Dynamic Controls
That's involved. Here's an interesting article on the issue of dynamic controls.
I think normally if you create dynamic controls then you're responsible for recreating them on postback; however the article contains a way to use the Init event if it's copacetic with your app.
Edit:
or Regular ASP.NET Controls
You can use data bound ASP.NET controls like: DataList, Repeater, GridView, etc. (You can put text boxes and all other kinds of controls into them for repeating in each row - or "item") and bind values to it. If you need to perform some processing on the user input first, then generate an internal Array, List, Dictionary, DataTable etc. (your choice) and bind that data as a data source to the ASP.NET control of choice.
aspnetControl.DataSource = myDataTable;
aspnetControl.DataBind();
or
aspnetControl.DataSourceId = "name_of_control";
There are various ways to assign a data source.
This way you won't run into the same problems as with dynamic control creation; however there is a lot to learn to facilitate this way too.

Categories

Resources