How to display a column data partially but need complete column data for update?

I have a column in my gridview that contains API KEYS for google maps. These keys are huge so i just need to display partial key for viewing purpose. But I need the complete key when user clicks on update button in gridview. How can I achieve this? Any ideas. I am copying part of my gridview aspx code. Rest of the code is coming from my class file for object datasource.

<asp:GridView ID="gvDomains" runat="server" DataSourceID="odsDomains" AutoGenerateColumns="False"

DataKeyNames="DomainID" Height="147px" Width="300px" ShowFooter="True"

ShowHeader="False" GridLines="None" OnRowCommand ="gvDomains_RowCommand">

<Columns>

<asp:TemplateField>

<ItemTemplate>

<table width="100%">

<tr>

<td style="text-align: right; width: 0px;">

Primary:

</td>

<td style="width: 100%">

<PD:PDS ID="PDS" runat="server" IsPrimary='<%# Eval("IsPrimary") %>' />

</td>

</tr>

<tr>

<td style="text-align: right;width: 300px;">

DomainName:

</td>

<td style="width: 100%">

<asp:Label ID="Label1" runat="server" Text='<%# Eval("DomainName") %>'></asp:Label>

</td>

</tr>

<tr>

<td style="text-align: right;width: 300px;">

APIKey:

</td>

<td style="width: 100%">

<asp:Label ID="Label2" runat="server" Text='<%#Eval("APIKey") %>'></asp:Label>

</td>

</tr>

</table>

</ItemTemplate>

 

 

public static List<Domain> SelectAll(DbProviderFactory providerFactory, String connectionString, int BusinessID)

{

List<Domain> retval = new List<Domain>();
using (DbConnection conn = providerFactory.CreateConnection())

{

conn.ConnectionString = connectionString;

conn.Open();

DbCommand cmd = conn.CreateCommand();

cmd.CommandText = "BusinessDomainsAll";

cmd.CommandType = CommandType.StoredProcedure;

 

DbParameter param = providerFactory.CreateParameter();

//param = cmd.CreateParameter();

param.ParameterName = "@BusinessID";param.DbType = DbType.Int32;

param.Value = BusinessID;

cmd.Parameters.Add(param);

param = providerFactory.CreateParameter();

param.ParameterName =
"RETURN VALUE";

param.DbType = DbType.Int32;

param.Direction = ParameterDirection.ReturnValue;

cmd.Parameters.Add(param);

DbDataAdapter da = providerFactory.CreateDataAdapter();

da.SelectCommand = cmd;

DataTable dt = new DataTable();

da.Fill(dt);

foreach (DataRow row in dt.Rows)

{

Domain dom = new Domain(providerFactory, connectionString);

dom.Populate(row);

retval.Add(dom);

}

if (Convert.ToInt32(cmd.Parameters["RETURN VALUE"].Value) != 0)throw new ApplicationException("Stored procedure BusinessDomainsAll failed");

}

return retval;

}

private void Populate(DataRow row)

{

DomainID = Convert.ToInt32(row["Id"]);

DomainName = Convert.ToString(row["DomainName"]);

APIKey = Convert.ToString(row["GoogleMapsAPIKey"]);

//commented code--APIKey = APIKey.Substring(0, 10) + "..."; ------If I try to use this stmt. then data is displayed partially but during update, it updates the data with partial key only.

}

0
mgarg75
8/5/2008 4:19:34 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
1087 Views

Similar Articles

[PageSpeed] 12
Get it on Google Play
Get it on Apple App Store

 In the label where you show the key you could do something like this

<%# Eval("APIKey").Substring(0,20) %>

For displaying 20 characters. There is a good chance this won't work. You might have to cast to string before being able call substring. If so just change it to.

 ((string)Eval("APIKey")).Substring(0,20)

I hope this helps / Mikael 

0
Mikael
8/5/2008 4:51:43 PM

Hi,

use this to display partial content of a given string in Grid View

<%# Eval("MyValue").ToString().Substring(0, Eval("MyValue").ToString().Length > 5 ? 5 : Eval("MyValue").ToString().Length) %>

In this case you will print the characters from 0 to 5 inclusive, I used the short condition in the second parameter of the Substring function to avoid out of range exception. So if the lenght is more than 5 for example only 6 charachters will be shown otherwise the whole string will be displayed which in this case will be 5 (0,1,2,3,4).

Note that you need to substiute 5 with the number of characters you want to display.

Thanks 


Don't forget to click (Mark as Answer) on the post that helped to solve your problem.
0
mr
8/5/2008 5:05:10 PM

String functions are not working, I am getting error if I am missing some reference or declaration.

0
mgarg75
8/5/2008 5:51:40 PM

what is the error you are receiving?

Thanks


Don't forget to click (Mark as Answer) on the post that helped to solve your problem.
0
mr
8/5/2008 6:43:55 PM

Hi mgarg75 ,

You can write code in RowDataBound event.

 

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Normal)
            {
                Label lbl = e.Row.FindControl("Label1") as Label;

                if (lbl.Text.Length >= 1)
                {
                    lbl.Text = lbl.Text.Substring(0, 1);
                }
            }
        }
    }

 

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/7/2008 7:30:04 AM

Thanks for everyone's help. I couldn't get javascript to work. But Samu Zhang's solution looked interesting, although I did not try.

I used the following solution, in item template I displayed APISubString and in edit item template, I used complete API key. While I was populating the object datasource, I created another property called APIKeysubstring.

private void Populate(DataRow row)

{

DomainID =
Convert.ToInt32(row["Id"]);

DomainName = Convert.ToString(row["DomainName"]);

APIKey = Convert.ToString(row["GoogleMapsAPIKey"]); // Complete key is displayed during update operation.

APIKeySubstr = APIKey.Substring(0, 10) + "..."; // Key is displayed partially

 

}

 

<Columns>

<asp:TemplateField>

<ItemTemplate>

<table width="100%">

<tr>

</tr>

<tr>

<td style="text-align: right; width: 300px;">

DomainName:

</td>

<td style="width: 100%">

<asp:Label ID="Label1" runat="server" Text='<%# Eval("DomainName") %>'></asp:Label>

</td>

</tr>

<tr>

<td style="text-align: right; width: 300px;">

APIKey:

</td>

<td style="width: 100%">

<asp:Label ID="Label3" runat="server" Text='<%#Eval("APIKeySubstr") %>'></asp:Label>

</td>

</tr>

</table>

</ItemTemplate>

<EditItemTemplate>

<table width="100%">

<tr>

<td style="text-align: right; width: 0px;">

DomainName:

</td>

<td style="width: 100%">

<asp:TextBox ID="tb_DomainNameUpdate" runat="server" Text='<%# Bind("DomainName") %>'></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID="RequiredFieldValidatorUpdate" ValidationGroup="UpdateD"

Display="Dynamic" runat="server" ControlToValidate="tb_DomainNameUpdate" ErrorMessage="*Required"></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td style="text-align: right; width: 0px;">

APIKey:

</td>

<td style="width: 100%">

<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("APIKey") %>'></asp:TextBox>

</td>

</tr>

</table>

</EditItemTemplate>

 

 

0
mgarg75
8/8/2008 2:05:50 PM
Reply:

Similar Artilces:

Issue with Template Columns & Bound Columns while updating the data in a GridView control
Hi, I'm facing the below problem (In general, ObjectDataSource is driving me crazy ! ) I have a simple gridview control and an ObjectDataSource is used to populate the grid. I'm trying to update a row and the corresponding tableadapter methods & stored procedure are in place. Each row has 2 checkboxes and 2 textboxes in edit mode. When the change the values in edit mode and hit update, the checkbox values changed are saved into the Database properly, whereas the textbox values are not being saved. If the textbox column is a bound column then the column is updated with <NULL> in...

Exporting in Excel without cells or excel columns merging for one column of data table(need sorting, data filters perfectly)
 Hi,   I have an issue with the excel exporting of the report using ssrs.  I am using only the body section for exporting to excel.  Here in the body i have an Image, Textbox(for Title), textbox2(for dates from,to) and below it i have a table having the columns used for showing the data.  The report gets generated but when i exported to excel, All the columns and rows in the excels sheets come close and its like there is no uniformity.  Few columsn of excel are covered under a single columsn of the data table.  So its making users feel uncomfortab...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

How do I turn 2 columns of data into 6 columns of data?
I am pulling the Display Name and Fax Number from Active Directory.  It gets put into a datatable, then fed to a DataGrid.  I end up with a format like this: dn fn dn fn dn fn etc. What I need to do is format it like this: dn fn dn fn dn fn dn fn dn fn dn fn I can try a DataList and use <%# DataBinder.Eval(Container.DataItem, "cn" %>, but then the same values would be put in the same place as the code looped through the search results. Does anyone know how to change the actual column layout of a DataGrid or DataList so the data is displayed horizontal...

No table index exists or at least one table index column is not included in data source. Data can be displayed but not updated.
No table index exists or at least one table index column is not included in data source. Data can be displayed but not updated. I get this error when trying to build a form, i'm connected to a remote database, the DBA states I have permissions on the tables i'm working with. There is no index on these table, all columns in table are being included in form i get this error. Been unable to find any info on this error in user documentation. Thanks in advance. Melissa Johnson Forms require that there is a unique index / primary key on a table. If neither of those exis...

Filter problem in display column and data column
Hello I have a strange situation and needs to solve immediately. I have a generic window to maintain different tables through different datawindows. The datawindows will be assigned dynamically based on the user selection. I have provided filter functionality in this generic window using PFC filter. Now, my problem is, in each datawindow some of the columns I am using as drop down datawindows to display coulmns and data columns on the behind. When user tries to filter on one column which has drop down datawindow, it is giving an error as "Invalid filter", which is right ...

DDDW Display column VS Data column
I have 2 codes that are different. like aaa, bbb (data column) but for their description (display column) it is same. "Test" and when I choose bbb, it only takes aaa. It looks like it does not care about data column. it looks up the display column and then takes the first match. and itemchanged even won't even get fired. Is this true about datawindow service? if so, why? or is there any other way to get around it? Thanks. If the display values are the same, how does the user know which one to choose? You need to make the display values unique. You could do ...

Displaying single column of data across multiple columns..
Hi all... Okies my problem.... I have a dataset that has a single column, with 100 rows. I wan't to display this in a table with 4 columns with 25 rows in each column.. Does anyone know of a simple solution? Thank's in advance. Jeremy Baka Saru Hi, you can try the DataList with RepeatColumns property set to 4.  Alvin ChooiMicrosoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia Blog : http://alvinzc.blogspot.com...

how to htmlencode data when using data controls to display data
Hi Lets say you are displaying a colllection of records in a gridview and you want to make sure all of the rows and columns are html encoded before you display them, how can can you get the gridview to do this automatically? I don't want to have to create a template for each bound column. Thanks very much andrea Hi Andrea, I believe there is a "HtmlEncode" property on each column that you can set.  By default I believe it is set to true.  You can pull up the column editor by selecting the "edit columns" task, and then select the columns in the botton left of the dialog to see...

Displaying a single Data Window Column in multiple columns
I have a datawindow that is retrieving a single column. Using Powerbuilder 5.04, is there anyway to display this data in multiple columns sorted (alphabeticlly) vertically (eliminates n-up). Any help would be appreciated. Thanks Yehuda Newspaper columns? Yehuda wrote in message <3ACB5511.E9262E3C@yahoo.com>... >I have a datawindow that is retrieving a single column. Using >Powerbuilder 5.04, is there anyway to display this data in multiple >columns sorted (alphabeticlly) vertically (eliminates n-up). Any help >would be appreciated. >Thanks >Yehuda &...

i have work on gridview control.in that i have 3columns.name as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i
hi,i have work on gridview control.in that i have 3columns.name as subject,bookname,link. in this some link column data are very large.according to that data(no spaces in that data)gridview has changed.i want display half of the data and remaining display like this.(ex:http://ww.yahoo.com...........).how can i display like this,and one more thing is always the column size will constant. Try something like this: <asp:templatefield headertext="Link"> <itemtemplate> <asp:hyperlink id="HyperLink1" runat="server" navigateurl='<...

Display only Columns that have Data in GridView Control
Good evening to the community, thanks for the help that ever provideThe situation is the following:I'm working in a application that have like 50 columns in the Database that represents Earning Codes for employees, but most of the times only 10 are used.What if something can be done to only display in the GridView Control the columns that the value is different than Null. Thanks for any lead evick   If you set the gridview to auto create the columns based on the datasource then when selecting data from the db only return the columns that have data in them. aspro Please m...

how to select particular data of a column from any data control at run time?[*-)]
I want to select series of data on a particular column, using mouse drag method in run time. Is it possible to get the values of selected data ? which data control shud i use? Does anyone know? Thankx in Advance...

Inserting BLOB Type column data with other columns data(normal Text)
In below code, SQL Statement is used to Insert BLOB Type data using Serialization. It is required to insert other (normal text) with BLOB Type data as well. Like to get below SQL statement amended so that all the columns(ID,name, blob) can be inserted. Just now below code working fine Inserting BLOB Type data. I think it is not stright forward way to insert all the columns(normal text) with BLOB?  1 protected void button2_Click(object sender, EventArgs e) 2 { 3 //Connection string 4 string oradb = datasource= mysource;userid="xyz" password="passwo...

Data Set ---- Data Row ( How to retrieve column data in a array )
Question regarding Dataset in ASP.NET ds = DBFunctions.RunSelect("select * from emp where Userid='" & vUserID & "'") If (ds.Tables(0).Rows.Count > 0) Then Dim dr As DataRow = ds.Tables(0).Rows(0)location= dr("location")  -- this statement only gives me the first locaitonMytable userid          location111              AAA111              BBB111         ...

Need help to display data in columns and Subcolumns
Hi All,  I Have some data to be shown in ASP.NET web page in the  following format.  I should sort data and the number of subcolumns is not constant in a main column ------------------------------------------------------------------------------------------------ |HyperLink|        Header 1        |          Header 2          |          Header 3        ...

data, data, data
Hello, I need some advice on the best method to keep a database updated in this scenario. I have a local Solomon SQL Server where we keep our inventory. I want to build an application that will be hosted at a remote hosting location which provides a SQL database. I want to build the application to allow clients to access the inventory items and make requests based on the remote SQL data. The order will be sent to our fulfillment department via email; they will fiill the request and ship.  I'm not sure the method to do this while keeping the data current on the remote and the l...

Getting data from data columns
 for now if i want to say retrive a field from a row, i use 1 SQLDataSource, 1 GridViewThen in the code it will be like Dim temp as String = GridView.Rows(0),Cells(5).Text, works but i need quite alot of redundant controls isit? how do i do it with say just 1 SQLDataSource or something else, classic ASP with SQL code, is a bit complex sometimes, although if thats the only way i don't mind, but state how to do it? i get quite blur when it comes to ASP with SQL, they by itself is still ok. Hello my friend, The SQLDataSource is good for simple get and display, but when you need to i...

File, Line,Column,Project columns not displaying data in Error List!
Hi I need help here. In my error list window, my File, Line,Column,Project columns are not displaying data at at all thus it's making it very difficult to debug my errors. can someone enlighten me on this issue? Thanks alot!Sincerely Yours, Abupapa Hello, Anyone bother to help me or know the answer to my question? Thank you.. Sincerely Yours, Abupapa...

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

display XML data in datagrid with checkbox column <template column>
i can set the datagrid.datasource = myXmlDataset, but anyone know how i can hook an unbound column (template column with a checkbox) to one of my XML fields ??? i was thinking of creating a datatable from scratch, cycling thru the items in the XML document and wring them into the table, then filling myXmlDataset, then binding that dataset to my datagrid. but this has proved to be more of a challenge than i thought. anyone tried doing this before ??? is it even feasible ???"If it is secrect enough, you alone know it." I might be missing something but why don't you read you...

Data Adapter Fill from table in dataset displays all columns in Data Grid (C#)
Hi all,I hope I am posting this to the right area.  I am creating a web applicaiton.  I have a stored procedure which selects from data. Naturally, I populate the data into a dataset.  Using the data adapter, I fill the results into a variable called results from a table. Next, I created a DataGrid called DataGrid1.  My datagrid properites is set to not create the columns automatically (This was done in design view)  Its data source is results, dataMember is the name of my table from the Stored Procedure.  I then create several BoundColumn variables name bc...

Displaying one of the columns in GridView data as GroupBy or similar data one after another row
Hi Would like to know the property or code that will Group data in one of the columns of GridView together. In other words i like to display the columns data in GridView that is repeated more than once together. Example: say Column heading Name John Jim Kevin Albert John Jim John You can see john or jim is displayed in Name Column at various rows. I like to get them displayed together such as John John Jim Jim Regards,-- "Mark As Answer" if my reply helped you -- Hi I am not too sure, but may be you can try a "Order by" clause at your SQL level. Say,...

which data control to use when result does not have fixed number of columns to be displayed
I have a search engine which quries tables in database and returns the result, now in this case, NUMBER OF COLUMNS are NOT FIXED, it depends on the table from which it is getting the data. My question is .........which  is/are  the data control can be used in this case to display the results and how........I mean if you can show me a sample code or link where I can study more about it. Please do help me, this is urgent. Thanks a lot. You could use a GridView with AutoGenerateColumns set to True http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(VS.80)...

Web resources about - How to display a column data partially but need complete column data for update? - asp.net.presentation-controls

Partially ordered set - Wikipedia, the free encyclopedia
In mathematics , especially order theory , a partially ordered set (or poset ) formalizes and generalizes the intuitive concept of an ordering, ...

P3 Allows Photo Owners To Partially Encrypt Photos On Facebook, Choose Recipients
A research team at the University of Southern California developed a tool that encrypts photos , but only portions of those photos, so that authorized ...

Partially bleached hard and soft corals on Molasses Reef
Explore mattk1979's photos on Flickr. mattk1979 has uploaded 5008 photos to Flickr.

Court Partially Upholds Arizona Immigration Law - YouTube
The Supreme Court Rules to Partially Uphold Arizona Immigration Law. Jess Bravin has details on The Markets Hub.

Sharjah hospital reopens partially after fixes
The Ministry of Health shut down Sharjah's Royal Hospital after it failed surprise inspections.

Dark clothes, broken headlight put motorcyclist partially at fault in nighttime crash, court rules
... journey as &quot;risky enterprise&quot; in nighttime crash case. Dark clothes and a faulty headlight made a motorcycle rider partially at fault ...

Vietnam Airlines to partially privatise
Around 25 per cent of the national carrier will be sold in an IPO. Vietnam Airlines says it will be partially privatised in November, part of ...

Father in Facebook photo case partially acquitted
Father in Facebook photo case partially acquitted

Milanos on the Lake restaurant partially collapses into Lake Macquarie
AN elderly woman had to run for her life after a popular waterfront restaurant partially collapsed into Lake Macquarie Monday morning when part ...

Building partially collapses in Fyshwick fire
Fire crews will investigate the cause of a large fire they extinguished inside a party hire shop in Fyshwick on Tuesday.

Resources last updated: 2/17/2016 11:15:25 PM