How To Add Different Columns With Same Name To Gridview

Feb 3, 2010

I am using C#.Net as my language. I want to add some columns of same name to a grid view. How can I do it???

View 3 Replies


Similar Messages:

C# - GridView - Columns.Insert() Cause Data To Vanish On Postback But Columns.Add() Works OK?

Oct 13, 2010

I have a GridView that has several dynamic columns (I do not know how many at design time and it could be 0-12 columns, hence need for dynamic columns). I have the columns in the grid and data bound to them - works great. There are other standard, design-time TemplateField columns with TextBox controls in them. These are bound with values that the user can edit. The grid is posted back via a Submit button. My question is "Why does gv.Columns.Insert() cause all my TextBox data to be null on Postback, but gv.Columns.Add() works like a champ?"

protected void BuildColumns()
{
// The first column to begin to insert the columns in the GridView
int columnIndex = 5;
BoundField aoColumn = new BoundField();
aoColumn.HeaderText = "New Column 1";
gvMyGrid.Columns.Insert(columnIndex, aoColumn); // kills txtQuantity.Text on postback
gvMyGrid.Columns.Add(aoColumn); // works fine
columnIndex++;
foreach (MyEntity my in _myEntityCollection)
{
BoundField myColumn = new BoundField();
myColumn.HeaderText = String.Format("{0:d}", my.StartDate);
gvMyGrid.Columns.Insert(columnIndex, myColumn);
columnIndex++;
}
}

I then go on to assign values to these BoundFields in the _RowDataBound method and all of this works great. However, when I post back and try to reference some TextBox and they are all null. And yes, I have the BuildColumns() call wrapped in if (!IsPostBack) on Page_Load. Of course I would like to use .Insert() so that the columns can go in the proper location and not at the end of the Columns array.

View 1 Replies

Forms Data Controls :: In Page User Able To Select Gridview Columns And It Will Hide Remaining Columns

Mar 18, 2010

in asp.net page user able to select gridview Columns, and it will hide remaining columns and that selection done by check box with column list bellow is Image link , what exactly I am looking for [URL] it look bellow after selection of column done [URL]

View 1 Replies

Hide Columns In GridView With Auto - Generated Columns?

Jan 19, 2010

GridView1.Columns.Count is always zero even SqlDataSource1.DataBind();

But Grid is ok I can do

for (int i = 0; i < GridView1.HeaderRow.Cells.Count;i++)

I rename request headers here but

GridView1.Columns[i].Visible = false;

I can't use it because of GridView1.Columns.Count is 0. So how can I hide them ?

View 5 Replies

Show Several Columns In Datasource As Autogenerate Columns In Gridview?

Jan 27, 2011

I have a datasource, which includes many columns, idealy, I need use a gridview to show:

1) first 3 columns: template fields, these fields depends on values in some columns of datasource. I use template fields, hard coded. works fine.

2) the other columns. This is I do not know how to do it. In the data source, there are about 10-20 columns data, each time, the # of columns of the data varies. idealy, I need show each of them as a seperated column in gridview. The entire data source may have 30 columns, but some of them are used in 1), and I only want show these 10-20 columns in gridview. Some columns in data source, I may not use them at all. is there a way to do this? or have to seperate them as a detail view style UI?

View 1 Replies

C# - Display GridView With Many Columns As Two Sets Of Columns?

Jan 20, 2010

I apologize for the odd title. I've been trying to figure out how to do this and can't quite put it into words. Basically, I need to try to display a GridView with a whole bunch of columns (37 in one case) in two "rows" of columns. More or less.

So instead of this:

Column1 Column2 Column3 Column4 Column5 Column6
Data Data Data Data Data Data
Data Data Data Data Data Data
Data Data Data Data Data Data

I'd like something like this:

Column1 Column2 Column3
Data Data Data
Data Data Data
Data Data Data

Column4 Column5 Column6
Data Data Data
Data Data Data
Data Data Data

As in the example there can be multiple rows returned which all need to be displayed. I'm trying to stop a very large horizontal scroll bar being required. I've been searching as much as I can but haven't found anything that fits what I'm looking for.

View 1 Replies

Forms Data Controls :: How To Convert Gridview Rows To Columns And Columns To Rows

Mar 4, 2011

I'm binding a gridview from a webservice with 30 columns and 10 rows, I need to print the same in a PORTRAIT, for that i decided to display columns as rows and

rows as columns like below:

EMP1 1 2 3 4
EMP2 1 2 3 4

View 3 Replies

Parent Columns And Child Columns Don't Have Type-matching Columns

Aug 3, 2010

i am making relation between two datatables and m getting this error

in this ds.Tables(0).Columns("In_ID") datatype is string
ds.Tables(1).Columns("row_id") datatype is integer

how i do the type casting here to make dataset relation

ds.Relations.Add("Rel_1", ds.Tables(0).Columns("In_ID"), ds.Tables(1).Columns("row_id"), True)

View 3 Replies

Forms Data Controls :: Updating GridView With GridView Columns That Are Readonly

Feb 20, 2011

I have a GridView with 5 fields. Only two of the fields are edittable (the others are READONLY).

I have an UpdateCommand as follows

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NHLPOOL %>"
SelectCommand="SELECT [PlayerID], [Firstname], [lastname], [Goals], [Assists], [Goals]+[Assists] as Points, [AsOfDate] FROM [PlayerStats], [Player] where [PlayerStats].[PlayerID] =[Player].[ID] ORDER BY Points DESC"
UpdateCommand="UPDATE PlayerStats SET Goals =@GOALS, Assists =@ASSISTS, AsofDate=GETDATE() WHERE PLAYERID = @PLAYERID">
</asp:SqlDataSource>

The issue is I want the PLAYERID GV column to be READONLY but I get a runtime error when updating if the PLAYERID is READONLY.

I get the error "

Must declare the scalar variable "@PLAYERID"."

View 1 Replies

Forms Data Controls :: GridView PopUpEdit Form - Show Fields Not Shown In GridView's Columns

May 4, 2010

Currently I have something like this, but when I click "update" the record doesn't get updated (but no error is returned).

[Code]....

View 5 Replies

Programatically Change The HeaderText Of Gridview Columns In A Nested Gridview?

Jul 31, 2010

I have a gridview and I would like to be able to programatically change the HeaderText of it's columns (probably in the DataBinding event). I know this can normally be achieve with something like this:

myGrid.Columns[0].HeaderText = "My Header Text";

However, the gridview in question is actually nested within another gridview (via template column). So I can't access it directly. I'm trying to use the FindControl method to access it, but so far that isn't working.

View 2 Replies

Data Controls :: GridView BoundField Column Readonly - Disable Specific Columns In Edit Mode Of GridView

May 7, 2015

How to disable editing the data in the cells of datagridview in c#?

View 1 Replies

C# - Enabling GridView Columns When GridView Checkbox Is Checked

Oct 14, 2010

in a GridView (ASP.NET/C#), I have a number of template fields - the 2 ones relevant to the question are 'checkbox1' and 'quantity'. The checkbox starts off as unticked for every row, and the quantity starts off as disabled for every row. But when the user ticks one of the rows checkboxes, I need a piece of JavaScript or something to check if the relevant rows checkbox is checked, and if so enable to the rows quantity textbox.

View 1 Replies

C# - Hide Columns By Id In Gridview?

Mar 17, 2011

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.

View 3 Replies

C# - Collapsing Columns In Gridview?

Aug 9, 2010

Instead of hide/collapse the traditional rows, what I want to do is a user control that hide and collapse the columns when I click in the respective buttons.

View 1 Replies

C# - Getting Xml Columns From LinqDataSource To Appear In A GridView?

Jul 25, 2010

I have a LinqDataSource and a GridView displaying a table. Columns of type xml don't show up. I'd like them to show up something like they do in Sql Server query outputs, with a link to display the clickable xml, though there may be another approach i'm not considering (maybe a styled display of the xml data, etc.). Two things i'd like to know how to do

First, get the xml converted to a string, and display it in the table. Maybe the first 30 chars.
Finally, style the xml into something useful, like a clickable link to display the full xml, or a sub-table, or a styled string.

So the following works, and displays a nice table, with edit and delete links. But Xml fields are missing. How would you go about adding support for the Xml fields?

[Code]....

View 1 Replies

.net - Gridview With Resizable Columns

Mar 18, 2011

have a gridview and i wanted to allow the client to resize the width of the columns.on how i can accomplish

View 1 Replies

VS 2010 - Gridview With 3 Columns

Jun 21, 2011

I know this might be possible but I got a Gridview with 3 columns

Service Tag# | Description | Date

and they have dummy data at the moment. So what I was wondering if there is a way I can make the first column (Service tag#) clickable (like a link). If so which event should I code it? I know I can have a Select column on the side but I don't want to use that.

I was able to code this up

protected void dgView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.dgView1, "Select$" + e.Row.RowIndex);
}
}

but the thing is that it will only show underlined if the mouse is over, I tried on show but with no luck.

View 4 Replies

How To Display Gridview Datas As Two Columns

Oct 29, 2010

I have a gridview in a webform. When the page is laoded the data from xml is binded to gridview. Say i have twenty product details in xml. Now i have written code to bind those details with gridview its working fine.

i want to display like this, for exmaple if there are twenty records i want to display ten datas on left and ten datas in right, find the sample below,

Records in dataset,

a 1
b 2
c 2
d 3

this is the way i want to display in gridview,

a 1 c 2
b 2 d 3

View 1 Replies

VS 2008 - Seeing Order Of Gridview Columns?

May 3, 2010

I've got a tough one (at least for me!). I have a gridview control which is actually from ComponentOne but most is the same as the normal gridview. It has a feature that lets me move columns around so they are in different order. I want to be able to click a button and see the order of these columns and which ones are visible. This is to be used for a custom report I am generating.

Does anyone know how to find out what columns are visible and in what order? I'm doing it in VB coding for asp.net.

View 3 Replies

Changing Gridview Columns Dynamically?

May 13, 2010

I haven't had any luck finding the answer yet. My problem is that I want to be able to update the dataformatstring on a gridview column at runtime. For example, I switch from displaying # of units to cost of said units... and I want to change the format of the column to {0:c}. It seems like it should be a simple task.

View 2 Replies

Two Button Columns On A GridView Control?

Jun 16, 2010

I have a grid view will two different button columns. I want to perform a different action depending on what button the user presses. How in the SelectedIndexChanged event do I determine what colmun was pressed. This is the code I use to generate the columns.

grdAttachments.Columns.Clear();
ButtonField bfSelect = new ButtonField();
bfSelect.HeaderText = "View";
bfSelect.ButtonType = ButtonType.Link;
bfSelect.CommandName = "Select";
bfSelect.Text = "View";
ButtonField bfLink = new ButtonField();
bfLink.HeaderText = "Link/Unlink";
bfLink.ButtonType = ButtonType.Link;
bfLink.CommandName = "Select";
bfLink.Text = "Link";
grdAttachments.Columns.Add(bfSelect);
grdAttachments.Columns.Add(bfLink);

View 1 Replies

Multiply Textbox With Gridview Columns?

Jan 15, 2011

I have write this code to create a gridview with 3 columns

DataTable dt = new DataTable();
dt = new DataTable();
dt.Columns.Add("ID", typeof(int)).AutoIncrement = true; [code]....

I would like to add in this code a textbox with the quantity.When i give the quantity i want in another textbox to have the total.

for example 2*1.5=3

How can i do that? My huge problem is that i dont know how to take the values of the 3rd column.The value 1.5 in this example.

View 2 Replies

Resizable Gridview Columns Using Javascript?

Jan 22, 2010

I want to Resize Gridview columns using javascript. Below is an example.

View 4 Replies

Find The Total In Gridview Columns?

Jan 15, 2011

I wrote this source code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowLand.aspx.cs" Inherits="ShowLand" %>
<!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">

[Code]....

In this code the user can chose with the checkbox his choice and with the button to add this choice in the second gridview.Also in the textbox can give the quantity. I would like to find a way how to multiply the quantity with the price column.How can i do that?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved