473,769 Members | 3,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView as EditItem Template

Hello,

I have GridView in EditItem Template of DetailsView (in normal - read-only
mode there is a label). When I'm in
edit mode I can select one item from GridView. The main problem is that as
I can see in DataBidings property of the GridView I deliver SelectedIndex
instead of SelectedValue. Therefore I gives SelectedIndex value to update in
that specific field and NOT SelectedValue (it is ID - foreign key of parent
table)

How can I resolve the problem so that I pass value not an index?
I would appreciate for a code snippet if requred for the problem solution
Best Regards

Darek T.

Apr 4 '07 #1
3 3680
Czolem Darek,

Could you provide the code to clarify what exactly you're trying to achieve.
--
Milosz
"Dariusz Tomon" wrote:
Hello,

I have GridView in EditItem Template of DetailsView (in normal - read-only
mode there is a label). When I'm in
edit mode I can select one item from GridView. The main problem is that as
I can see in DataBidings property of the GridView I deliver SelectedIndex
instead of SelectedValue. Therefore I gives SelectedIndex value to update in
that specific field and NOT SelectedValue (it is ID - foreign key of parent
table)

How can I resolve the problem so that I pass value not an index?
I would appreciate for a code snippet if requred for the problem solution
Best Regards

Darek T.

Apr 4 '07 #2
Czolem,

.......
<EditItemTempla te>

<asp:GridView ID="gv_DeviceMo del" runat="server"
DataSourceID="S ql_DeviceModel" SelectedIndex=' <%# Bind("IDDeviceM odel") %>'>

<Columns>

<asp:CommandFie ld ShowSelectButto n="True" />

</Columns>

</asp:GridView>

</EditItemTemplat e>

.......

So as you can see I have GridView as EditItemTemplat e but there is
SelectedIndex=' <%# Bind("IDDeviceM odel") %>' the value of ID in my table
(IDDeviceModel) is connected with SelectedIndex (and should be connected
with SelectedValue rather).

So when I choose an item and make update I get other item unfortunatelly. I
think that in the scenario when my ID were of GUID type or something like
that I would get error but in my case idex type ad ID type are the same so
there is no error but annoing issue.

I hope that now it's clear

Pozdrawiam

Darek
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:62******** *************** ***********@mic rosoft.com...
Czolem Darek,

Could you provide the code to clarify what exactly you're trying to
achieve.
--
Milosz
"Dariusz Tomon" wrote:
>Hello,

I have GridView in EditItem Template of DetailsView (in normal -
read-only
mode there is a label). When I'm in
edit mode I can select one item from GridView. The main problem is that
as
I can see in DataBidings property of the GridView I deliver SelectedIndex
instead of SelectedValue. Therefore I gives SelectedIndex value to update
in
that specific field and NOT SelectedValue (it is ID - foreign key of
parent
table)

How can I resolve the problem so that I pass value not an index?
I would appreciate for a code snippet if requred for the problem solution
Best Regards

Darek T.


Apr 5 '07 #3
Czolgiem,

OK, i see what you're trying to do. The resolution is pretty straitforward -
you need to find corresponding row index when binding internal grid view,
therefore you need to bind grid's view rowdatabound event:

private bool found = false;
protected void gridView_RowDat aBound(object sender, GridViewRowEven tArgs e)
{
DataGridItem item = e.Row;

if (found)
return;

if (item.ItemType == ListItemType.It em ||
item.ItemType == ListItemType.Al ternatingItem)
{
// i assume you bind the data to a datatable or a dataset
DataRow row = ((DataRowView) (item.DataItem) ).Row;

// note i assume you use datakeynames property of the DetailsView1
int id = (int) row["IDDeviceMo del"];
if (id == (int) DetailsView1.Se lectedValue)
{
gridView.Select edIndex = item.ItemIndex;
found = true;
}
}
}
Alternatively, another approach would be to find the corresponding row
manually (of course it can only be applied if you know the datasource you
bind to gridview control, i.e data bound to details view is hierarchical and
you bind children to the grid view):

protected int FindIndex(DataR ow rows, int IDDeviceModel)
{

for (int i = 0; i < rows.Count; i++)
{
DataRow row = rows[i];

// i assume
if ((int) row["IDDeviceMo del"] == IDDeviceModel)
return i;
}

return -1;

}

and aspx code:
<asp:GridView ID="gv_DeviceMo del" runat="server"
DataSourceID="S ql_DeviceModel" SelectedIndex=' <%#
FindIndex(((Dat aRow)Container. DataItem).GetCh ildRows(),
(int)Eval("IDDe viceModel")) %>'>

Hope this helps
--
Milosz
"Dariusz Tomon" wrote:
Czolem,

.......
<EditItemTempla te>

<asp:GridView ID="gv_DeviceMo del" runat="server"
DataSourceID="S ql_DeviceModel" SelectedIndex=' <%# Bind("IDDeviceM odel") %>'>

<Columns>

<asp:CommandFie ld ShowSelectButto n="True" />

</Columns>

</asp:GridView>

</EditItemTemplat e>

.......

So as you can see I have GridView as EditItemTemplat e but there is
SelectedIndex=' <%# Bind("IDDeviceM odel") %>' the value of ID in my table
(IDDeviceModel) is connected with SelectedIndex (and should be connected
with SelectedValue rather).

So when I choose an item and make update I get other item unfortunatelly. I
think that in the scenario when my ID were of GUID type or something like
that I would get error but in my case idex type ad ID type are the same so
there is no error but annoing issue.

I hope that now it's clear

Pozdrawiam

Darek
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:62******** *************** ***********@mic rosoft.com...
Czolem Darek,

Could you provide the code to clarify what exactly you're trying to
achieve.
--
Milosz
"Dariusz Tomon" wrote:
Hello,

I have GridView in EditItem Template of DetailsView (in normal -
read-only
mode there is a label). When I'm in
edit mode I can select one item from GridView. The main problem is that
as
I can see in DataBidings property of the GridView I deliver SelectedIndex
instead of SelectedValue. Therefore I gives SelectedIndex value to update
in
that specific field and NOT SelectedValue (it is ID - foreign key of
parent
table)

How can I resolve the problem so that I pass value not an index?
I would appreciate for a code snippet if requred for the problem solution
Best Regards

Darek T.



Apr 5 '07 #4

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

Similar topics

1
1287
by: aarif.shah | last post by:
Hi, i am Aarif, I Have a gridview.On clicking the edit link of gridview i want my edititem template(that i have defined ) to show either Texbox control or dropdown list depending on some condition. when user clicks on update link of the gridview,the value shoud be taken from either textbox or selected value of dropdown list depending upon which control is appearing in the edit mode. How can i do this?
2
3571
by: GCeaser | last post by:
All, I am attempting to use the following code to add a TemplateColumn to my GridView programatically: lobj_TemplateColumn = New TemplateColumn lobj_TemplateColumn.HeaderText = lobj_Standard_Values_Fields_DataRow.Header_Text lobj_TemplateColumn.ItemTemplate = New GridViewTemplate( _
2
2445
by: | last post by:
I want to know how to make a clickable button or Command field on a GridView, and have the user's action a) fire a function and b) pass a data value from one of the GridView's columns to that function. Long version: ASP.NET's usual paradigm with master-detail editing is to have you define a commandfield, and on your detail view to define a second datasource that uses the SelectedValue of the GridView to determine what the detail record...
0
1985
by: Subzizo | last post by:
i have a template field in a gridview,i modified the edititem template for a field to represent a dropdownlist instead of the textbox,i need to make set of server side code when the user changes the select dropdownlist, although i turned on autopost back and the enable viewstate properties of the ddl the selected item is not maintained when the page is reloaded and so the server side code dosn't work correct? thank you for help
0
921
by: Dariusz Tomon | last post by:
Hello, I have embedded GridView in EditItem Template of DetailsView. When I'm in edit mode I can select one item from GridView. The main problem is that as I can see in DataBidings property of the GridView I deliver SelectedIndex instead of SelectedValue. How can I resolve the problem so that I pass value not an index? I would appreciate for a code snippet if requred for the problem solution
0
4287
by: jimbob91577 | last post by:
I have a Gridview that I am dynamically adding template columns to which contain text boxes in their "Item Data" field. After adding the columns to the gridview in my Page_Load event, the page binds a SQL Data Source to the Gridview and all is good. I'm left with a gridview with 5 columns 3 of which have text boxes in their item cells. (The other two come directly from the SQL DS) What I want is to be able to change a value in one of the...
1
1946
by: neobonzi | last post by:
Hello! I'm dynamically creating a GridView bound to a datatable using custom template columns using the following method: protected void ShowGrid(DataTable dt) { int i; int j; for( i = 0; i < dt.Columns.Count; i++) {
3
2811
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I need to control the visibility of a textbox based on a dropdown selection in the datalist's edititem template. To do this, I registered a client script block function and attached a client side handler for the dropdownlist's onchange event in the...
5
7745
by: deepakthegeek | last post by:
I dont know if this kind of issue has been addressed earlier. I have a gridview control on a form, in the EditItem Template when a textbox is clicked, I have a popupcontrolextender displaying an AP Panel which contains a checkboxlist and two buttons "OK" and "Cancel". What I want to do is, after the selections are made and after the "OK" button is clicked I want to display the selected items of the checkboxlist seperated by commas,...
0
9579
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
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
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...
0
10036
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
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
6662
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
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.