473,769 Members | 6,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# - ASP - Gridview

Hello,
I have a gridview control bound to a objectdatasourc e.
The primary key column is on the grid but made visible = false.
Because the column is invisible I cant get to the cell value when the user
presses
the edit button on the grid.
Code

protected void grdBedpDetails_ RowEditing(obje ct sender,
GridViewEditEve ntArgs e)
{

String bedpID = grdBedpDetails. Rows[e.NewEditIndex].Cells[1].Text;
}

I have set up the grdBedpDetails. DataKeyNames property
but this is only useful in the selectedindex event not the RowEditing event

grdBedpDetails. Rows[e.NewEditIndex].Cells[1].Text return a empty string
because the column is invisible.

Thanks


--
Life in the sun
May 30 '06 #1
7 5471
any help Bump...
--
Life in the sun
"WayDownUnd er" wrote:
Hello,
I have a gridview control bound to a objectdatasourc e.
The primary key column is on the grid but made visible = false.
Because the column is invisible I cant get to the cell value when the user
presses
the edit button on the grid.
Code

protected void grdBedpDetails_ RowEditing(obje ct sender,
GridViewEditEve ntArgs e)
{

String bedpID = grdBedpDetails. Rows[e.NewEditIndex].Cells[1].Text;
}

I have set up the grdBedpDetails. DataKeyNames property
but this is only useful in the selectedindex event not the RowEditing event

grdBedpDetails. Rows[e.NewEditIndex].Cells[1].Text return a empty string
because the column is invisible.

Thanks


--
Life in the sun

May 31 '06 #2

Hi,

Thank you for your post!

You have two options to get the hidden columns' values depending on whether
or not the columns belong to the DataKeyNames property of GridView.

1) If the hidden columns are included in DataKeyNames:

int id = (int) grdBedpDetails. DataKeys[e.NewEditIndex].Values[0];

2) If the hidden columns are not included in DataKeyNames:

Since hidden columns are not rendered to the client, you need to hide the
columns using CSS rule instead of setting its property Visible="false" .
Below are the detailed steps:

a) Create a CSS rule in html header:

<style type="text/css">
.hidden { display: none; }
</style>

b) Hide a column by applying CSS class to its header and item:

<asp:BoundFie ld DataField="ID" HeaderStyle-CssClass="hidde n"
ItemStyle-CssClass="hidde n" />

c) Then you can get the ID column text by:

String bedpID = grdBedpDetails. Rows[e.NewEditIndex].Cells[1].Text;
Hope this helps. If anything is unclear, please feel free to post here.

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 31 '06 #3
Walter,
Thanks for your reply
number 1) work great you saved my day again !!

I have another question releated to the same gridview , I was hoping you
have a easy answer
I have column 0 = CommandField ( view)
I have column 1 = CommandFiled ( edit)

When the event grdTemp_Selecte dIndexChanged
occurs on the server I want to know which column was selected
eg do somthing when view pressed do somthing else when edit pressed.

Thanks in advance


--
Life in the sun
"Walter Wang [MSFT]" wrote:

Hi,

Thank you for your post!

You have two options to get the hidden columns' values depending on whether
or not the columns belong to the DataKeyNames property of GridView.

1) If the hidden columns are included in DataKeyNames:

int id = (int) grdBedpDetails. DataKeys[e.NewEditIndex].Values[0];

2) If the hidden columns are not included in DataKeyNames:

Since hidden columns are not rendered to the client, you need to hide the
columns using CSS rule instead of setting its property Visible="false" .
Below are the detailed steps:

a) Create a CSS rule in html header:

<style type="text/css">
.hidden { display: none; }
</style>

b) Hide a column by applying CSS class to its header and item:

<asp:BoundFie ld DataField="ID" HeaderStyle-CssClass="hidde n"
ItemStyle-CssClass="hidde n" />

c) Then you can get the ID column text by:

String bedpID = grdBedpDetails. Rows[e.NewEditIndex].Cells[1].Text;
Hope this helps. If anything is unclear, please feel free to post here.

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 31 '06 #4
"Walter Wang [MSFT]" <wa****@online. microsoft.com> wrote in message
news:Lu******** ******@TK2MSFTN GXA01.phx.gbl.. .
Since hidden columns are not rendered to the client, you need to hide the
columns using CSS rule instead of setting its property Visible="false" .
Below are the detailed steps:


Much easier simply to unhide the columns temporarily, bind the data and then
hide the columns again e.g.

MyGridView.Colu mns[n].Visible = true;
MyGridView.Data Bind();
MyGridView.Colu mns[n].Visible = false;

Saves all that unnecessary messing about with CSS.
May 31 '06 #5
Hello Mark,
Sounds like a good work around.
But it didnt work for me
The cell returned empty in the event

grdBedpDetails_ RowEditin
grdBedpDetails. Columns[6].Visible = true;
grdBedpDetails. DataKeyNames = dataKeyNames ;
grdBedpDetails. DataSourceID = "ODSBedps";
ODSBedps.Select Parameters.Clea r();
ODSBedps.Select Method = "GetBedpLis t";
grdBedpDetails. DataBind();
grdBedpDetails. Columns[6].Visible = false;

--
Life in the sun
"Mark Rae" wrote:
"Walter Wang [MSFT]" <wa****@online. microsoft.com> wrote in message
news:Lu******** ******@TK2MSFTN GXA01.phx.gbl.. .
Since hidden columns are not rendered to the client, you need to hide the
columns using CSS rule instead of setting its property Visible="false" .
Below are the detailed steps:


Much easier simply to unhide the columns temporarily, bind the data and then
hide the columns again e.g.

MyGridView.Colu mns[n].Visible = true;
MyGridView.Data Bind();
MyGridView.Colu mns[n].Visible = false;

Saves all that unnecessary messing about with CSS.

May 31 '06 #6
"WayDownUnd er" <wa**********@n ewsgroups.nospa m> wrote in message
news:28******** *************** ***********@mic rosoft.com...
Sounds like a good work around.
But it didnt work for me
The cell returned empty in the event


Strange - it has always worked for me. Can you try to set the column's
visibility to true *immediately* before doing the bind e.g.

grdBedpDetails. Columns[6].Visible = true;
grdBedpDetails. DataBind();
grdBedpDetails. Columns[6].Visible = false;
May 31 '06 #7
Hi,

Thank you for your update!

I've seen you opened a new post regarding this problem in this newsgroup. I
will reply in that thread. Thank you for your understanding.

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 31 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5677
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the GridView to allow entry of quantity and Y/N switch for
6
3041
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
7
14819
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
5
4838
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
1
5216
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView is not displayed. I set the datasource and then bind the GridView. I've tried disabling the...
3
4605
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a datasource to this GridView in runtime. But I cannot
2
13200
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
5
3007
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the page is posting back when the DDL is selected / chaged, but the event is never being called. Any...
6
5756
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the OnSelectedIndexChanged event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndexChanged event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the...
3
5244
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.