Forms Data Controls :: Get Datakey From Templatefield (dropdownlist) In Gridview

May 21, 2010

I have a gridview with a DropDownList (contained in a TemplateField). I have set the OnSelectedIndexChanged event to a function called "ddlAgent_SelectedIndexChanged" This allows me to aquire when a user has changed the value for the dropdownlist. What I need to do is persist this newly selected value to the database for the gridview record. The problem I'm having is how to I get the datakeyNames value for that row? See code below!

TemplateField source
<asp:TemplateField HeaderText="Agent">
<ItemTemplate>
<asp:DropDownList ID="ddlAgent" runat="server" AutoPostBack="False" OnSelectedIndexChanged="ddlAgent_SelectedIndexChanged">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
ddlAgent_SelectedIndexChanged

Protected Sub ddlAgent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim gvItems As DropDownList = CType(sender, DropDownList)
' Write the selected Agent ID to the Inquiry record.
'Dim ID As Integer = gvMaint.DataKeyNames(e.SelectedIndex).Value ' THIS FAILS BECAUSE
e.SelectedIndex is not part of System.EventArgs
End Sub

View 3 Replies


Similar Messages:

Forms Data Controls :: TemplateField In Gridview Not Passing DataKey Value?

Feb 4, 2010

I'm relatively new to the VS environment. I'm using VS2010 Beta 2 with VB. I have a Gridview setup to pull a list of employees. Next to their name I have edit and delete icons. When I leave the icons as ButtonFields, they pass the DataKey value to my code behind perfectly. When I convert the ButtonFields to TemplateFields, they no longer pass the DataKey.

[Code]....

[Code]....

[Code]....

View 2 Replies

Forms Data Controls :: Get The Datakey For A DataControlRowType.DataRow When A TemplateField Is Created?

Dec 12, 2010

I would like to retreive the data key (au_id) when the rowType = DataRow, so I can do a Sub query with the datakey Id.

I'm using this Microsoft Example:

<%@ Page language="C#" %> <script runat="server">
// Create a template class to represent a dynamic template column.
public class GridViewTemplate : ITemplate
{
private DataControlRowType templateType;

[Code]....

View 10 Replies

Data Controls :: Get DataKey Value On SelctedIndexChanged Event Of DropDownList In GridView

May 7, 2015

How-to-bind-data-to-a-DropDownList-which-is-inside-a-GridView-in-ASPNet.aspx

it is possible, use OnSelectedIndexChanged method of the dropdownlist and take the id value of the row where is the dropdownlist.

<asp:DropDownList ID="ddlCountries" runat="server" onselectedindexchanged="GetId_SelectedIndexChanged">
 c#
protected void GetId_SelectedIndexChanged(object sender, EventArgs e)
{
}

need to have the id of the row where is the dropdownlist, to make a query after.

View 1 Replies

Forms Data Controls :: Binding DropDownList Datasource In Code Behind For TemplateField In GridView

Feb 23, 2010

I am trying to bind the datasource of a ddl which is located inside the EditTemplate of a TemplateField.When is the best time to bind this datasource (after loading grid, before editing, ? (Note: I must do this in code behind).I am currently trying to bind it on the edit command:

[Code]....

The issue is that the list retrieved from the LoadLists method is null when passing to the LoadList method where the datasource is bound.

View 5 Replies

Forms Data Controls :: Populating Dropdownlist Inside Gridview's TemplateField Dynamically Created

Sep 6, 2010

I need to create a TemplateField column dynamically , which will contain dropdowlist controls. I've been using this
example to create my first dynamic columns and for the last column, the one that contains dropdowlist controls, I've written this class:

[Code]....

But what I don't know is, where should I populate the dropdownlist control?

View 3 Replies

Data Controls :: Implement Dependent Cascading DropDownList In GridView TemplateField

Dec 23, 2013

How do I fill ProductNameID on selection of ProductCategoryID dropdown by passing

ProductCategoryID .SelectedValue...

aspx Code

<asp:GridView ID="gridPosition" runat="server" AutoGenerateColumns="False" ShowFooter="True" OnRowDataBound="gridPosition_onRowDataBound"
DataKeyNames="SaleDetailID" OnRowEditing="gridPosition_RowEditing"
OnRowCancelingEdit="gridPosition_RowCancelingEdit" OnRowUpdating="gridPosition_RowUpdating"
OnRowDeleting="gridPosition_RowDeleting" ShowHeaderWhenEmpty="True" CssClass="manage-admin"
Width="500px" GridLines="None">

[Code] .....

View 1 Replies

Forms Data Controls :: How To Bind TemplateField DropDownList With ArrayList

Aug 21, 2010

I'm trying gridview templateField DropDownList bind with arraylist. When i set bindsource i got this error. "//Error Object reference not set to an instance of an object."

My Sample .aspx

<asp:TemplateField HeaderText="Type">
<FooterTemplate>
<asp:DropDownList ID="_grvcboType" runat="server" Width="117px" DataTextField="Display" DataValueField="Value">
</asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Type") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

[Code]....

View 2 Replies

Forms Data Controls :: Get The Gridview Datakey Value?

Jan 5, 2011

I have a gridview with datakey value

in save button click i want to get the gridview datakey value

Dim _id As Integer For Each row As GridViewRow In Me.gridviewi.Rows Next

View 2 Replies

Forms Data Controls :: Retrieving Datakey Value In Gridview?

Mar 19, 2010

Tried this but it doesn't work.

[Code]....

Retrieving datakey value in gridview?

View 5 Replies

Forms Data Controls :: Is It Possible To Have The BookId Value As A DataKey Of The GridView

Aug 14, 2010

Lets say for example that I have a book object that looks like this:

[Code]....

And a Page_Load method that bounds a GridView called "gvBooks" from a generic list of books:

[Code]....

Now as you can see, I want to have the BookId value that is part of the Dictionary as a DataKey of the gvBooks GridView.

That piece of code of curse returns an Exception:

"DataBinding: 'GridViewTest.Book' does not contain a property with the name 'BookId'."

My question is: Is it possible to have the BookId value as a DataKey of the GridView?

View 4 Replies

Forms Data Controls :: Highlighting A Row In A Gridview Control Using A DataKey In C#

Apr 11, 2010

My gridivew currently has 4 colums with the third being a subject column. I want this colum to have bold text if the datakey 'ReadStatus' is equal to false. I have had success if the column is bound to the gridview but 'ReadStatus' is only a datakey and not bound to the gridiview. My code is below:

[Code]....

[Code]....

View 1 Replies

Forms Data Controls :: Programmatically Set GridView.SelectedIndex From Known DataKey

Aug 4, 2010

I want to select a row in my GridView based on a known data key value at runtime.

In other words, I have a data key value, 2 for ex., and the primary key value of one of the rows in my GridView is 2. How can select that row? (Without having to go through each row to find which one matches my key, then setting the SelectedIndex.

View 6 Replies

Forms Data Controls :: Retrieving Datakey, (an ID Value) From GridView Via Check Box?

Apr 13, 2010

I have a GridView with a checkbox for the user to select different categories. I am trying to retrieve the CategoryID associated with each row when the user clicks next, however I keep getting an error that tells me the selected index cannot be negative or out of range.

Here is my function

[Code]....

How do I retrieve the CategoryID of the row as an Integer value?

View 7 Replies

Forms Data Controls :: Determine DataKey For The Row To Be Deleted In GridView?

Jun 14, 2010

I have wired an event to handle delete command for my GridView. But I cannot determine which the record's unique key, in my case stored in DOCIDNO field. All I get is a row index, such as 0, 1, 2 which obviously cannot be used to accurately delete a record from database.

<asp:GridView
ID="gridTimeOff"
runat="server"
HeaderStyle-CssClass="gridHead"
RowStyle-CssClass="gridRow"

[Code].....

View 2 Replies

Forms Data Controls :: Get The DataKey Value In RowDataBound Event For GridView?

Feb 22, 2010

How to get the DataKey value in RowDataBound event for GridView

View 3 Replies

Forms Data Controls :: Assign Gridview Datakey To Formview Textbox?

Jan 31, 2010

I have a gridview table and i need to select one record and insert the Datakey of the selected record to a formview textbox control. I'm completely lost...

View 13 Replies

Forms Data Controls :: How To Stop ObjectDataSource Query When GridView DataKey Is Missing

Mar 3, 2010

I have a Gridview which is populated from an ObjectDataSource. Data Source has a control parameter hooked up to the SelectedDataKey value of the GridView. My Gridview has rows which may not have a DataKey. I am receiving an error when a GridView row without a DataKey is selected.

View 5 Replies

Data Controls :: How To Get ID (DataKey) From GridView

Mar 26, 2016

This is Film table in database

ID Daste Preference

1 film 5
2 serial 4
3 serial 1
4 film 2

And bind gridview from this table and ordred by Preference Column I put Linknbutton in gridview that code is:

protected void LinkButton11_Click(object sender, EventArgs e) {
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
int id = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);
using (SqlConnection conn = General.GetConnection()) {

[Code] .....

Oroblem is in this line:

int id = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);

I want when I click on linkbutton it use Id but here it use Preference data How I can define that according to Id column it go to

Response.Redirect("EditFilm.aspx? &id=" + id);

View 1 Replies

Forms Data Controls :: GridView.DataKey Error: No Default Member Found For Type 'DBNull'?

Sep 16, 2010

I am binding SQL data to a GridView. The GridView's DataKeyNames property is set to the SQL column called "utID"

I know that within the SQL results, some of the utID values are NULL. After databinding to the GridView, I need to enumerate through the GridViewRows an read the DataKey values. However, when I try this I get the following error:

No default member found for type 'DBNull'. I am using the code below.

What object types are stored within DataKeys (I thought it was just integers or strings)

How to handle a NULL datakey value to prevent this error occurring?

I don't want to use Try Catch because it's too much of a 'hack'

[Code]....

View 6 Replies

Data Controls :: How To Access DataKey Property Of Parent GridView From RowCommand Of Child GridView

Nov 8, 2013

I have followed your Nested level gridview and found it working, but i want add a button in the child element(from your example  i will have a btn  in Product grid and it should get contact_id (parent datakey value as well) ),as i  need to update in database.

View 1 Replies

Data Controls :: How To Get Datakey Value Of Nested Child GridView

May 7, 2015

How can get datakey value of Nested(child) GridView on click on delete button of child grid

View 1 Replies

Forms Data Controls :: How To Sort TemplateField Value In GridView

Jun 20, 2010

I want to create simple rating page where player's place,name and rating is displayed. I've created database with ID,Name and Rating Columns, binded Gridview to this database and created TemplateField "Place". With following code I've created numbered list for Place:

protected void Page_Load(object sender, EventArgs e){
for (int i = 0; i < GridView1.Rows.Count; i++)

View 4 Replies

Forms Data Controls :: Pulling The Value Of A TemplateField From A GridView?

Nov 23, 2010

I have a GridView, bound to a table (Meals) in a SqlDataSource.

Into that GridView, I have added a TemplateField, which contains a DropDownList (which displays the numbers 1 - 10, added manually; no Data Binding). And, I've added a ButtonField.

When I click the Button, I want the values of some of the GridView rows PLUS whatever value was selected in the DropDownList to be pulled out and stored in a second Sql table (Orders).

Pulling the rows bound to the SqlDataSource is easy but JavaScript is needed (I think) to pull the SelectedValue from the DropDownList. I understand women more than understand JavaScript (that's how little I know) and the code below has been kindly offered by another forum user who is at a loss, himself, now.

Here's the code and the error message I'm getting.

ASPX:

[Code]....

And here's the Code Behind:

[Code]....

No design time errors reported but here's the run time error:

Object reference not set to an instance of an object.

On the following line:

Line 28: if (row.RowType == DataControlRowType.DataRow)

View 6 Replies

Forms Data Controls :: Gridview Add Templatefield Dynamically?

Mar 11, 2011

[Code]....

[Code]....

I want to add two image button in the TemplateField.. and add it in the gridview.

View 3 Replies







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