.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

DataKeyNames property in GridView

Posted By:      Posted Date: October 03, 2010    Points: 0   Category :ASP.Net

Hi All,

I am assigning DataKeyNames, i need to call my encryption function before passing the value for DataKeyNames. How i can do this.

Here is my code :

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="White" 
                           BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
                           DataSourceID="SqlDataSource1" DataKeyNames="ID">

I need something like DataKeyNames="MyClass.Encrypt("ID")"

I am trying to avoid code behind use. Please give me some tips if it can be done in .aspx page?

Thank You

View Complete Post

More Related Resource Links

Changing a textbox's readonly property right before update on a gridview


I have a gridview with a date field. I don't want the user to be able to type in their own date and mess up the format so I made the property readonly. That date is then set by a point and click interface. This is all working fine but when the user clicks update this field doesn't update because it's readonly. If i turn readonly off it works so is there a way to turn off the readonly property right before submit?

gridview datakeynames with xmldatasource

I have this:<asp:GridView ID="gvSearchResults" PageSize="10" AutoGenerateColumns="false" DataSourceID="XMLDS" runat="server">    <Columns>        <asp:TemplateField>            <ItemTemplate>                <i>Name <%# XPath("str[@name=""introtext""]")%></i><asp:Button ID="ltbnCompare" Text="Compare" CommandName="Compare" CommandArgument='<%# XPath("str[@name=""id""]")%>' runat="server" />            </ItemTemplate>        </asp:TemplateField>    </Columns>    </asp:GridView>    <asp:XmlDataSource EnableCaching="false" XPath="response/result/doc" ID="XMLDS" runat="server"></asp:XmlDataSource>Now in the gvSearchResults_OnRowCommand I want to read the datakeynames for a row in which a button was clicked.But I need to reed several datakeynames, such as id, img and title.How can I put these

How do I set the PageIndex property of a GridView?


In my web-based project, I pass an ID field as a parameter in my URL and go through each row in my gridview to find the correct row that matches the ID parameter. I am in the DataBound evet of my GridView

REM if ID parameter was given in URL
If Not Request.QueryString("ID") Is Nothing AndAlso _
IsNumeric(Request.QueryString("ID")) Then

Dim bItemNotFound As Boolean = True

REM i is the Page index counter
Dim i As Integer = -1

REM j is the row counter for each page
Dim j As Integer = -1

Dim selected_index As Integer = -1

For i = 0 To GridView1.PageCount - 1

REM This line gives an error
GridView1.PageIndex = i

For j = 0 To GridView1.DataKeys.Count - 1
If Request.QueryString("ID") = GridView1.DataKeys(j).Value Then
bItemNotFound = False
selected_index = j
Exit For
End If

If bItemNotFound = False Then
Exit For
End If

If bItemNotFound = False Then
GridView1.SelectedIndex = selected_index
GridView1.PageIndex = 0
GridView1.SelectedIndex = -1
End If
End If

Why can I no

Gridview DataKeyNames question



I am trying to get the delete to work on my gridview. I've added a


but when i click delete i get

Input string was not in a correct format.

Binding complex property to Gridview columns


We know that using something like Bind("CustomerName") can be used in the Text property of a label control inside a gridview, where CustomerName is a property of the object whose collection is bound to the gridview. If that property is of a complex type (object of another class), how do we use a property of that inline object as a binding for the gridview column?

How to check CheckBox.IsChecked property if CheckBox is in header of ListView/GridView with grouping


Sorry for this difficult title :P

So what exactly I need? I will try to explain it step by step as easy as possible.
My question is on the end of this post, but to understand my issue is better to read all steps.

First have a look on this post http://msdn.microsoft.com/en-us/library/ms754027(v=VS.90).aspx

1) I am implementing allmost the same code. 
But I changed one TextBlock (in Expander.Header) for a CheckBox:

<ListView x:Name="ExampleListView"
 ItemsSource="{Binding Source={StaticResource Src}}"

 <GridViewColumn DisplayMemberBinding="{Binding Path=PropertyOne}" Header="One" />
 <GridViewColumn DisplayMemberBinding="{Binding Path=PropertyTwo}" Header="Two" />


Delete records in Gridview with multi-datakeynames in GridView!


Hello all,

I have a GridView that displays the sample data as following:

Category    |      Title           |    Grade


Math         |      Algebra         |       6

Math         |      Geometry      |       5

Math         |      Algebra         |       4

Reading    |      Basic             |       5

There are no duplicate records. Is it any solution to obtain values of category, book and grade of each row with checkbox marks and pass them to stored procedure parameters: ParamCategory, ParamTitle, ParamGrade for deleting process. I believe that we can get values of one specific row with checkbox mark. Any suggestions or comments how to solve are really appreciated. If possible to give me a sample codes soon, thanks in advance. 


Inplace Edit in GridView

In this article I am presenting a different way to look at EditItemTemplate, using which user navigation for editing is reduced and . it looks very different (see screeen shots) then regular implementation of GridView.

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

AJAX GridView Checkbox Select All in ASP.Net

In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

AJAX GridView Paging and Sorting using C# in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Paging Using Ajax in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

Displaying Row Details Tooltip on GridView using JQuery

Continuing exploring JQuery! I decided to implement a feature to display some kind of details related to a row displayed on GridView. For example when displaying employees details on GridView some information might not fit in the GridView because it will make it huge and wide. These infomration can be diplayed as Tooltip. Or when you want to display a picture and some kind of formated text to be diplayed as tooltip when mouse hover on the image.

jQuery: Highlight Gridview Rows with Checkbox

Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

Gridview setup:

Sortable GridView using jQuery's TableSorter

This article explains how to use jQuery's plug-in Tablesorter to implement client-side sorting in an ASP.NET GridView. This comes in handy especially when an ObjectDataSource is used with a GridView as GridView does not provide sorting out of the box.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend