How To Get the Gridview's Field Value if the Column's Visible=False..?

Here is the scenario:

My sql query returns Name, ID, SSNum.

I use a gridview which has 3 columns Name, ID and SSNum (with SSNum is set visible=false) so the gridview only shows Name and ID.

I need to use part of SSNum to form a NewUserID in the code behind. Im doing this by using the gvResult_OnRowDataBound.

So far, if I set SSNum column's visible=false then I wont see this field on row data bound.

Any suggestion as how to obtain this SSNum from the code behind?

1
joeLA
2/24/2009 6:21:30 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

5 Replies
1203 Views

Similar Articles

[PageSpeed] 18

 you can set it as the datakey on the properties of the grid view and use this code

this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value

 

Hope this helps


Mark as an answer if it helps.
0
almargob
2/24/2009 7:01:44 PM

 you can set it as the datakey on the properties of the grid view and use this code

this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value

 

Hope this helps


Mark as an answer if it helps.
0
almargob
2/24/2009 7:08:39 PM
I forgot to mention that i use ItemTemplate NOT BoundField 

so I can not use the following line:

strSSNum = item.Cells[0].Text.Trim();

What is the alternative statement to get data from from ItemTemplate column..?

0
joeLA
2/24/2009 7:36:08 PM

 if you use datakey then you won't need any of that.

 

To access an ItemTemplate Column

TextBox ssn = item.Cells[0].FindControl("ssn") as TextBox

ssn.Text is the value you will be looking for 


Mark as an answer if it helps.
0
almargob
2/24/2009 9:59:06 PM
joeLA:
I forgot to mention that i use ItemTemplate NOT BoundField

so I can not use the following line:

strSSNum = item.Cells[0].Text.Trim();

What is the alternative statement to get data from from ItemTemplate column..?

If you don't want to set DataKeyNames property for the DataBind control. You can not get the value because the content will not be render as you set Visible property to 'Flase'. However, I suggest you try to set Display to 'None' instead of set Visible to 'Flase'. Please refer to the following code:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        onrowdatabound="GridView1_RowDataBound" >
        <Columns>
        <asp:TemplateField>
        <ItemTemplate>
            <asp:Label ID="lb_strSSNum" runat="server" Text='<%#Eval("ID") %>' style="display:none"></asp:Label>
        </ItemTemplate>
        </asp:TemplateField>
            <asp:BoundField DataField="Column1" HeaderText="Header1"/>
            <asp:BoundField DataField="Column2" HeaderText="Header2"/>
        </Columns>
    </asp:GridView>

 If you want to get its value, you can refer to almargob's idea.


Gary yang - MSFT
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Gary
2/27/2009 3:27:32 AM
Reply:

Similar Artilces:

Replace 1's and 0's in a gridview column with Yes's and No's
Is it possible to change the display of a column in a gridview to show a Yes for all 1's and a No for 0's that display in a particular column of a gridview bound to a database?  If so, can someone share the way with me?  I am using ASP.NET 2.0 with VB Code Behind.  Thanks One way you can do is thrrough  CASE in your select statement: Select YesNoColumn= CASE yourColumn WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END FROM YourtableLimno <Columns>     <asp:TemplateField HeaderText="yourHeader" SortExpression="yourDataField"> ...

How to set my GridViews's auto-generated column's visibility to false.
I just wonder how to set my GridView's autogenerated column's(actually ID field of my table)visibility to false? I do the following: GridView.Columns[1].Visible = false;But it says "Index was out of range. Must be non-negative and less than the size of the collection." My first column in the GridView is a CommandField(Select) one i added manually and the rest is autogenerated and appended to it. When i change the code as follows, changing the index to "0" from "1" (that is, from ID field to CommandField of Select );GridView.Columns[0].Visible = false;It ...

binding second table's column's value to the gridview how?
Hi,Im using stored procedure like this:create proc selectimageandPosting  @uName nvarchar(256)  as  begin  select postingid,imageid,location, modelno, condition, description1,description2,years,months,days,price,negotiable,username,timeofposting from posting where username=@uName  select imageurl from productimage where id=(select imageid from posting where username=@uName)  end  which gives me right o/p in query analyzer now in asp.net code behind i've written:            con.Open()  &nbs...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

Default value for Dropdownlist that get's it's value from Database.
Hi, I am using an Object Data Souce to retrieve the value of a Dropdownlist from a table on MS SQL server 2005. I want to make a default value appear on the Dropdownlist intially, should i enter the default value into the database table or is that a better way of doing it? Any suggestions will be very much appreciated. E  No need for database just set sekected value after databingind protected void Page_Load(object sender, EventArgs e) { DataBind(); ListItem defaultItem = new ListItem("Select a Person", "-1"); th...

why a string column with a '' value synchronize from ASE to ASA, in ASA it's value become ' ' with a blank in it?
"darcy.zhai" <zhaizy@e-future.com.cn> wrote in news:43967064@forums-2-dub of sybase.public.sqlanywhere.mobilink: Please try to ask your question in the _body_ of the post, not the subject line. There are many people that never really look at the subject line (like myself most of the time). > why a string column with a '' value synchronize from ASE to ASA, in > ASA it's value become ' ' with a blank in it? This has to do with nullability. First, connect to ASE via ISQL and try the same query ML is executing. What is returned? An...

How to make the DetailsView's edit button visible according to the state of one field of a GridView's selected row?
Hello everyone! Now I am working with a Master/Detail page that using a gridview and a detailsview. The detailsview is set to editable and the edit button is autogenerated. I want to make the DetailsView's edit button visible according to the state of one field of a GridView's selected row. I tried to access the selected row of the gridview in the detailsview's ItemCreated event or DataBound event,using the following code GridViewRow row = gvwMaster.SelectedRow But it goes wrong with this line of code. And then I tried to write some code in the gridview's SelectedIndexChanged eve...

How can I get out of my Mozilla's browser the Winamp browser and get back the Google's or Mozilla's browser.
Please I have got to my browser ( I don't know how.) the Winamp browser he behave like virus stick in.But he doesn't has uninstalation section so I can't do anything to get him away from Mozilla's file. I'm not happy of Winamp's behave its like advertisement against a customer's will. Please is there any way to get him away from Mozilla?Please send me exact direction I have tried many ways but he is deeply inside the systeme so when I install new Mozilla he is always here ready to pester me. Thank you for an answer. Richard ...

The value's length for key 'data source' exceeds it's limit of '128'.
Hii, When I tried to bind dropdownlist to database by declaring connection string in the code behind file I am getting this error: The value's length for key 'data source' exceeds it's limit of '128'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The value's length for key 'data source' exceeds it's limit of '128'.Source Error: An...

Gridview
Gridview - how to find a column by it's column name rather than it's Cell index Hello Friendshow to find a column by it's column name rather than it's Cell indexi.e i want to do something likestrFirstName = Grid1.Rows[2].Cells["FirstName"]In the project i am working on gets customized to different customers....so the position of the columns keep changing depending on the customers requirement.hardcoding..like below is a pain to maintainif i use Grid1.Rows[2].Cells["1"]Can some body help..regardsSara Hi, columns do not get associated names exactly like that. Nearest equivalent w...

GRIDVIEW's column's right-click
Hi, I would like to make right-click on gridview's Hyperlink Field  where i will able to do actions and redirect to other Reports in short some kind of WINDOWS functionality on WEB, i am also using AJAX, if any body has any idea please let me know. Thanks ~Parth  ThanksParthvisit for some interesting articals at www.parthrawal.blogspot.comMark as Answer if it helps you hi i am done with it please follow the link  http://aspalliance.com/946ThanksParthvisit for some interesting articals at www.parthrawal.blogspot.comMark as Answer if it helps you...

calculate the grid's column's value
hi, i am looking for a solution for my datagrid, i have 4 column column 1 is string column 2 is string column 3 is string column 4 is an integer what i want to do is calculate the total of column 4 and display it at the bottom of the datagrid, need help, this is urgent. sandman16 check if this article helps...***********************Dinakar NethiLife is short. Enjoy it.*********************** ndinakar, thanks for you help man, i have already tried the solution and it worked!!! sandman16...

It's Linux !? No, it's BSD ! No, no, it's...
kFreeBSD http://wiki.debian.org/Debian_GNU/kFreeBSD a Debian distro using the FreeBSD kernel ! ObiWan wrote: > kFreeBSD > > http://wiki.debian.org/Debian_GNU/kFreeBSD > > a Debian distro using the FreeBSD kernel ! Why use a BSD kernel? I hope the reason is more than, just because they can. http://wiki.debian.org/Debian_GNU/kFreeBSD_why It's easy to understand why the would want to use Debian packages. :) -- Jimmy Johnson Registered Linux User #380263 >> kFreeBSD >> >> http://wiki.debian.org/Debian_GNU/kFreeBSD >> ...

how to control a RadioButtonList's Listitem's text show according database's field
Hi my page has a repeater control,in repeater has a RadioButtonList control now i want to let the RadioButtonList has four Listitem,every Listitem's text is a database's field so the listitem can show dynamic according every record how can i work out my problem thanks a lot  hello dearbound your RadioButtonList to database if i m not clear fell free 4 replySatyabrat SinghB.E.(C.Sc.)Web developer Livetek Solution Dont forget to click "Mark as Answer" on the post that helped you. yes.i bound the radiobuttonlist to a dataset but how to display the ...

Web resources about - How To Get the Gridview's Field Value if the Column's Visible=False..? - asp.net.web-forms

Resources last updated: 12/21/2015 6:52:06 AM