Search Results

Search found 68 results on 3 pages for 'edititemtemplate'.

Page 2/3 | < Previous Page | 1 2 3  | Next Page >

  • How to perform two-way data binding of controls in a user control inside a FormView

    - by Sandor Drieënhuizen
    I'm trying to perform two-way data binding on the controls in my user control, which is hosted inside a FormView template. FormView: <asp:ObjectDataSource runat="server" ID="ObjectDataSource" TypeName="WebApplication1.Data" SelectMethod="GetItem" UpdateMethod="UpdateItem"> </asp:ObjectDataSource> <asp:FormView runat="server" ID="FormView" DataSourceID="ObjectDataSource"> <ItemTemplate> <uc:WebUserControl1 runat="server"></uc:WebUserControl1> </ItemTemplate> <EditItemTemplate> <uc:WebUserControl1 runat="server"></uc:WebUserControl1> </EditItemTemplate> </asp:FormView> User control: <%@ Control Language="C#" ... %> <asp:TextBox runat="server" ID="TitleTextBox" Text='<%# Bind("Title") %>'> </asp:TextBox> The binding works fine when the FormView is in View mode but when I switch to Edit mode, upon calling UpdateItem on the FormView, the bindings are lost. I know this because the FormView tries to call an update method on the ObjectDataSource that does not have an argument called 'Title'. I tried to solve this by implementing IBindableTemplate to load the controls that are inside my user control, directly into the templates (just like I had entered them declaratively like in the code above). However, when calling UpdateItem in edit mode, the container that gets passed into the ExtractValues method of the template, does not contain the TextBox anymore. It did in view mode! I have found some questions on SO that relate to this problem but they are rather dated and they don't provide any answers that helped me solve this problem. How do you think I could solve this problem? It seems to be such a simple requirement but apparently it's more like opening a can of worms...

    Read the article

  • Binding a DropDownList inside a DetailsView

    - by annelie
    Hello, I'm having problems trying to populate a dropdownlist from the database. When I'm trying to set the datasource I can't find the dropdown control, it's in a DetailsView so I think it might have something to do with it only being created when it's in edit mode. It still says it's in current mode when I'm editing though, so not sure what's going on there. Here's the code from the aspx file: <asp:DetailsView id="DetailsView1" runat="server" AutoGenerateRows="false" DataSourceID="myMySqlDataSrc" DataKeyNames="id" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateInsertButton="False" > <Fields> <snip> <asp:TemplateField HeaderText="Region"> <ItemTemplate><%# Eval("region_name") %></ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="RegionDropdownList" runat="server" SelectedValue='<%# Bind("region_id")%>'> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> </Fields> </asp:DetailsView> And this is from the code behind: ArrayList regionsList = BPBusiness.getRegions(); if (DetailsView1.CurrentMode == DetailsViewMode.Edit) { DropDownList ddlRegions = (DropDownList)DetailsView1.FindControl("RegionDropdownList"); if (ddlRegions != null) { ddlRegions.DataSource = regionsList; ddlRegions.DataBind(); } } It's .net 2.0 if that helps. Thanks, Annelie

    Read the article

  • asp.net how to add items programmatically to detailsview

    - by dotnet-practitioner
    I have the following code for each lookup table. So far I am doing copy/paste for each drop down list control. But I think there is a better way of doing this. I should be able to specify DataTextField, DataValueField, control names etc. Of course I will have to manually add configuration related database values on the database side like look up table, and other changes in the stored proc. But at the aspx page or .cs page, there has to be a better way then copy/paste.. <asp:TemplateField HeaderText="Your Ethnicity"> <EditItemTemplate> <asp:DropDownList ID="ddlEthnicity" runat="server" DataSourceid="ddlDAEthnicity" DataTextField="Ethnicity" DataValueField="EthnicityID" SelectedValue='<%#Bind("EthnicityID") %>' > </asp:DropDownList> </EditItemTemplate> <ItemTemplate > <asp:Label Runat="server" Text='<%# Bind("Ethnicity") %>' ID="lblEthnicity"> </asp:Label> </ItemTemplate> </asp:TemplateField> Please let me know... Thanks

    Read the article

  • Two-way data binding of controls in a user control inside a FormView

    - by Sandor Drieënhuizen
    I'm trying to perform two-way data binding on the controls in my user control, which is hosted inside a FormView template. FormView: <asp:ObjectDataSource runat="server" ID="ObjectDataSource" TypeName="WebApplication1.Data" SelectMethod="GetItem" UpdateMethod="UpdateItem"> </asp:ObjectDataSource> <asp:FormView runat="server" ID="FormView"> <ItemTemplate> <uc:WebUserControl1 runat="server"></uc:WebUserControl1> </ItemTemplate> <EditItemTemplate> <uc:WebUserControl1 runat="server"></uc:WebUserControl1> </EditItemTemplate> </asp:FormView> User control: <%@ Control Language="C#" ... %> <asp:TextBox runat="server" ID="TitleTextBox" Text='<%# Bind("Title") %>'> </asp:TextBox> The binding works fine when the FormView is in View mode but when I switch to Edit mode, upon calling UpdateItem on the FormView, the bindings are lost. I know this because the FormView tries to call an update method on the ObjectDataSource that does not have an argument called 'Title'. I tried to solve this by implementing IBindableTemplate to load the controls that are inside my user control, directly into the templates (just like I had entered them declaratively like in the code above). However, when calling UpdateItem in edit mode, the container that gets passed into the ExtractValues method of the template, does not contain the TextBox anymore. It did in view mode! I have found some questions on SO that relate to this problem but they are rather dated and don't provide straight forward answers. How do you think I could solve this problem? It seems to be such a simple requirement but apparently it's more like opening a can of worms...

    Read the article

  • GridView's NewValues and OldValues empty in the OnRowUpdating event.

    - by Abe Miessler
    I have the GridView below. I am binding to a custom datasource in the code behind. It gets into the "OnRowUpdating" event just fine, but there are no NewValues or OldValues. Any suggestions as to how I can get these values? <asp:GridView ID="gv_Personnel" runat="server" OnRowDataBound="gv_Personnel_DataBind" OnRowCancelingEdit="gv_Personnel_CancelEdit" OnRowEditing="gv_Personnel_EditRow" OnRowUpdating="gv_Personnel_UpdateRow" AutoGenerateColumns="false" ShowFooter="true" DataKeyNames="BudgetLineID" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" > <Columns> <asp:BoundField HeaderText="Level of Staff" DataField="LineDescription" /> <%--<asp:BoundField HeaderText="Hrs/Units requested" DataField="NumberOfUnits" />--%> <asp:TemplateField HeaderText="Hrs/Units requested"> <ItemTemplate> <%# Eval("NumberOfUnits")%> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="tb_NumUnits" runat="server" Text='<%# Bind("NumberOfUnits")%>' /> </EditItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="Hrs/Units of Applicant Cost Share" DataField="" NullDisplayText="0" /> <asp:BoundField HeaderText="Hrs/Units of Partner Cost Share" DataField="" NullDisplayText="0" /> <asp:BoundField FooterStyle-Font-Bold="true" FooterText="TOTAL PERSONNEL SERVICES:" HeaderText="Rate" DataFormatString="{0:C}" DataField="UnitPrice" /> <asp:TemplateField HeaderText="Amount Requested" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true"/> <asp:TemplateField HeaderText="Applicant Cost Share" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true"/> <asp:TemplateField HeaderText="Partner Cost Share" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true"/> <asp:TemplateField HeaderText="Total Projet Cost" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true"/> </Columns> </asp:GridView>

    Read the article

  • DroDownlist in DataGrid produces Error

    - by S Nash
    I have a DataGrid and everytime I change value of it's embeded dropdwonlist I get: "System.Web.HttpException: The IListSource does not contain any data sources." I have a data grid which loads fine: Name column is editable. I have a dropdownlist these : DataDataGrid gets its value from a table. (Select Name, Address From Persons) Dropdown list also gets list of names from the same table. So DataGrid and dropdownlist are bound to 2 different datasets. Here is my code for dataGrid" <Columns> <ASP:ButtonColumn Text="Delete" CommandName="Delete"></ASP:ButtonColumn> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn> <ASP:TemplateColumn HeaderText="Name" SortExpression="FY" HeaderStyle-HorizontalAlign="center" HeaderStyle-Wrap="True"> <ItemStyle Wrap="false" HorizontalAlign="left" /> <ItemTemplate> <ASP:Label ID="Name" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' runat="server"/> </ItemTemplate> <EditItemTemplate> <ASP:DropDownList id="ddlName" cssClass="DropDownList" runat="server" datasource="<%#allNames%>" DataTextField= "Name" DataValueField="ID" Defaultvalue='<%# DataBinder.Eval(Container.DataItem, "ID") %>' OnPreRender="SetDefaultListItem" accessKey="I" AutoPostBack="true" /> </EditItemTemplate> </ASP:TemplateColumn> <asp:BoundColumn DataField="Address" ReadOnly="True" HeaderText="Address"></asp:BoundColumn> </Columns> Error happens here : dg.DataSource = ds dg.DataBind() Any ideas how to solve this issues? All I want is a DataGrid with a editable column ,which can be edited by choosing one of the value of in a dropdownlist.

    Read the article

  • Getting jQuery datepicker to attach to a TextBox within a ListView

    - by Clay
    I am using the jQuery Datepicker without any problem for TextBox controls that are non-templated. However, I am unable to get the datepicker to work with a TextBox that is in an EditItemTemplate of a ListView control. My latest attempt is to get a handle on this textbox by CSS class name "DateControl", any ideas? <asp:ListVIew id="lvTest" runat="server"> <LayoutTemplate>...</LayoutTemplate> <ItemTemplate>...</ItemTemplate> <EditItemTemplate> <tr> <td> <asp:TextBox ID="txtExpReceiveDate" runat="server" Text='<%#Eval("exp_receive_date","{0:dd-MMM-yy}") %>' CssClass="DateControl" /> </td> </tr> </EditTemplate> </asp:ListView> <script type="text/javascript" language="javascript"> $(document).ready(function () { $('DateControl').datepick({ dateFormat: 'M-dd-yyyy' }); }); </script>

    Read the article

  • C#: Formview doesn't change Mode

    - by Vinzcent
    Hey When I try to change my formview to Edit, he stays in de ReadOnlyMode. I can't figure out why. This is my code. <asp:FormView ID="fvDetailOrder" runat="server" AllowPaging="True" DataKeyNames="ID" OnModeChanging="fvDetailOrder_ModeChanging"> <EditItemTemplate> // I want to see this, when I click edit <asp:LinkButton ForeColor="#003366" ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> <InsertItemTemplate> Insert here <asp:LinkButton ForeColor="#003366" ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </InsertItemTemplate> <ItemTemplate> Read only <asp:LinkButton ForeColor="#003366" ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you certain you want to delete this product?');" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" /> </ItemTemplate> <PagerStyle ForeColor="#003366" /> </asp:FormView> Eventhandler protected void fvDetailOrder_ModeChanging(Object sender, FormViewModeEventArgs e) { fvDetailOrder.ChangeMode(e.NewMode); } Thanks, Vincent

    Read the article

  • How to display rich text in tooltip ASP.Net ?

    - by mokokamello
    Experts ! i use the following code to display a tooltip <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1"> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="datefu" HeaderText="date" SortExpression="datefu" /> <asp:TemplateField HeaderText="title" SortExpression="titlefu"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("titlefu") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <a href="#" title="<asp:Literal ID="Label1" runat="server" Text='<%# Eval("fu") %>'/>"/> <asp:Label ID="NamePatientLabel" runat="server" Text='<%# Eval("titlefu") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> display the following result however when i edit the text as follows (making it bold and red in another gridview containing rich text editor) i get the following (as a formatting result in the second grid view) however when i view in the first gridview to display the tooltip i get the following reult i really need your help to display the tooltip as rich text

    Read the article

  • gridview image column problem

    - by jame
    Work on vs05 C# asp.net .My SQL Syntax is :**** if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Images]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Images] GO CREATE TABLE [dbo].[Images] ( [ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL , [ImageName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Image] [image] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO I want to show this Images table values in a grid view.....I do it ...but the image value can not show ....asp.net syntax for gridview is <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="ImageName" HeaderText="ImageName" /> <asp:TemplateField HeaderText="Image"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Image") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Image") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> i write the below code on pageload event. i want images table values must shown when the page is load... string strSQL = "Select * From Images"; DataTable dt = clsDB.getDataTable(strSQL); this.GridView2.DataSource = dt; this.GridView2.DataBind(); Why not i get the image on my image column of the gridview.....what's the problem is how to solve?

    Read the article

  • ASP:DropDownList in ItemTemplate: Why is SelectedValue attribute allowed?

    - by recursive
    This piece of code <asp:DropDownList runat="server" ID="testdropdown" SelectedValue="2"> <asp:ListItem Text="1" Value="1"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> <asp:ListItem Text="3" Value="3"></asp:ListItem> </asp:DropDownList> yields this error: The 'SelectedValue' property cannot be set declaratively. Yet, this is a legal and commonly used edit template for databound GridViews. The SelectedValue attribute certainly appears to be declaratively set here. <EditItemTemplate> <asp:DropDownList runat="server" ID="GenreDropDownList" DataSourceID="GenreDataSource" DataValueField="GenreId" DataTextField="Name" SelectedValue='<%# Bind("Genre.GenreId") %>'> </asp:DropDownList> </EditItemTemplate> The question is: what is the difference between the cases when you are allowed to set it declaratively and those in which you are not? The error message implies that it's never allowed.

    Read the article

  • How do I initialize the controls in an InsertItemTemplate?

    - by Slauma
    I have - for instance - an asp:FormView which supports Read, Insert, Update, Delete and is bound to a DataSource: <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" > <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("MyText") %>' /> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MyText") %>' /> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MyText") %>' /> </InsertItemTemplate> </asp:FormView> If I am in Read-Mode or Edit-Mode the control is initialized with the property MyText of the current object which is bound to the FormView. But when I go to Insert-Mode I do not have a "current object" (FormView1.DataItem is indeed null) and the controls are empty. If I want to have my TextBox control initialized with a specific value how can I do that? In which event can I hook in to set default values to the controls in the InsertItemTemplate? Especially I have in mind using an ObjectDataSource. I was expecting that the InsertItemTemplate is initialized with a business object which underlies my ObjectDataSource and which is created by the ASP.NET framework simply by using its default constructor when the InsertItemTemplate gets activated. In the default constructor I would init the class members to the default values I'd like to have in my controls of the InsertItemTemplate. But unfortunately that's not the case: No "default" object is created and bound to the FormView. So it seems I have to initialize all controls separately or to create the default object manually and bind it to the InsertItemTemplate of the FormView. But how and where can I do that? Thanks in advance!

    Read the article

  • Formview doesn't change Mode

    - by Vinzcent
    When I try to change my formview to Edit, he stays in de ReadOnlyMode. I can't figure out why. This is my code. <asp:FormView ID="fvDetailOrder" runat="server" AllowPaging="True" DataKeyNames="ID" OnModeChanging="fvDetailOrder_ModeChanging"> <EditItemTemplate> // I want to see this, when I click edit <asp:LinkButton ForeColor="#003366" ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> <InsertItemTemplate> Insert here <asp:LinkButton ForeColor="#003366" ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </InsertItemTemplate> <ItemTemplate> Read only <asp:LinkButton ForeColor="#003366" ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you certain you want to delete this product?');" /> &nbsp;<asp:LinkButton ForeColor="#003366" ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" /> </ItemTemplate> <PagerStyle ForeColor="#003366" /> </asp:FormView> Eventhandler protected void fvDetailOrder_ModeChanging(Object sender, FormViewModeEventArgs e) { fvDetailOrder.ChangeMode(e.NewMode); }

    Read the article

  • asp.net gridview bind dateformat not working with update

    - by Brabbeldas
    I have a GridView with a TemplateField column which shows a DateTime from a DataSource. <Columns> <asp:CommandField ShowEditButton="True" /> <asp:TemplateField HeaderText="Start Date"> <EditItemTemplate> <asp:TextBox ID="txtDateStart" runat="server" Text='<%# Bind("dtDateStart", "{0:dd/MM/yyyy}") %>'</asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("dtDateStart", "{0:dd/MM/yyyy}") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> Displaying the date in the correct format works as it should. Note that the format starts with DAY followed by MONTH. When I switch to edit mode, change the date in the TextBox to '31-01-2013' and press the GridView's update-link i get an error: Cannot convert value of parameter 'dtDateStart' from 'System.String' to 'System.DateTime' The error is generated by the GridView not my own code. It happens before the UpdateMethod of my DataSource is called. When i type '01-31-2012' the data is processed correctly and the value is updated into the database. Somehow when the date is displayed it uses format dd-MM-yyyy (just as I need it to) But when it reads the new value form the TextBox it uses MM-dd-yyyy Can somebody please help me?

    Read the article

  • ASP.NET 3.5 GridView - row editing - dynamic binding to a DropDownList

    - by marc_s
    This is driving me crazy :-) I'm trying to get a ASP.NET 3.5 GridView to show a selected value as string when being displayed, and to show a DropDownList to allow me to pick a value from a given list of options when being edited. Seems simple enough? My gridview looks like this (simplified): <asp:GridView ID="grvSecondaryLocations" runat="server" DataKeyNames="ID" OnInit="grvSecondaryLocations_Init" OnRowCommand="grvSecondaryLocations_RowCommand" OnRowCancelingEdit="grvSecondaryLocations_RowCancelingEdit" OnRowDeleting="grvSecondaryLocations_RowDeleting" OnRowEditing="grvSecondaryLocations_RowEditing" OnRowUpdating="grvSecondaryLocations_RowUpdating" > <Columns> <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblPbxTypeCaption" runat="server" Text='<%# Eval("PBXTypeCaptionValue") %>' /> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlPBXTypeNS" runat="server" Width="200px" DataTextField="CaptionValue" DataValueField="OID" /> </EditItemTemplate> </asp:TemplateField> </asp:GridView> The grid gets displayed OK when not in editing mode - the selected PBX type shows its value in the asp:Label control. No surprise there. I load the list of values for the DropDownList into a local member called _pbxTypes in the OnLoad event of the form. I verified this - it works, the values are there. Now my challenge is: when the grid goes into editing mode for a particular row, I need to bind the list of PBX's stored in _pbxTypes. Simple enough, I thought - just grab the drop down list object in the RowEditing event and attach the list: protected void grvSecondaryLocations_RowEditing(object sender, GridViewEditEventArgs e) { grvSecondaryLocations.EditIndex = e.NewEditIndex; GridViewRow editingRow = grvSecondaryLocations.Rows[e.NewEditIndex]; DropDownList ddlPbx = (editingRow.FindControl("ddlPBXTypeNS") as DropDownList); if (ddlPbx != null) { ddlPbx.DataSource = _pbxTypes; ddlPbx.DataBind(); } .... (more stuff) } Trouble is - I never get anything back from the FindControl call - seems like the ddlPBXTypeNS doesn't exist (or can't be found). What am I missing?? Must be something really stupid.... but so far, all my Googling, reading up on GridView controls, and asking buddies hasn't helped. Who can spot the missing link? ;-) Marc

    Read the article

  • How to Edit data in nested Listview

    - by miti737
    I am using listview to display a list of items and a nested listview to show list of features to each item. Both parent and child listview need to able Insert,Edit and delete operation. It works fine for parent listview. But when I try to edit an child item, The edit button does not take it into Edit mode. Can you please suggest me what I am missing in my code? <asp:ListView ID="lvParent" runat="server" OnItemDataBound="lvParent_ItemDataBound" onitemcanceling="lvParent_ItemCanceling" onitemcommand="lvParent_ItemCommand" DataKeyNames="ItemID" onitemdeleting="lvParent_ItemDeleting" oniteminserting="lvParent_ItemInserting" > <LayoutTemplate> <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> <div align="right"> <asp:Button ID="btnInsert" runat="server" Text="ADD Item" onclick="btnInsert_Click"/> </div> </LayoutTemplate> <ItemTemplate> <table runat="server" cellpadding="0" cellspacing="0" border="0" width="100%"> <tr> <td> <div id="dvDetail"> <span >Description</span> <asp:TextBox ID="txtDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' TextMode="MultiLine" ></asp:TextBox> </div> <div id="dvFeature" > <span>Feature List</span> <asp:ListView ID="lvChild" runat="server" InsertItemPosition="LastItem" DataKeyNames="FeatureID" OnItemCommand="lvChild_ItemCommand" OnItemCanceling="lvChild_ItemCanceling" OnItemDeleting="lvChild_ItemDeleting" OnItemEditing="lvChild_ItemEditing" OnItemInserting="lvChild_ItemInserting" OnItemUpdating="lvChild_ItemUpdating" DataSource='<%# DataBinder.Eval(Container.DataItem, "FeatureList") %>' > <LayoutTemplate> <ul > <asp:PlaceHolder runat="server" ID="itemPlaceHolder" ></asp:PlaceHolder> </ul> </LayoutTemplate> <ItemTemplate> <li> <span class="dvList"><%# DataBinder.Eval(Container.DataItem, "FeatureTitle")%></span> <div class="dvButton" > <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="/Images/edit_16x16.gif" AlternateText= "Edit" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "FeatureID") %>' Width="12" Height="12" /> <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="/Images/delete_16x16.gif" AlternateText= "Delete" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "FeatureID") %>' Width="12" Height="12" /> </div> </li> </ItemTemplate> <EditItemTemplate> <li> <asp:TextBox ID="txtFeature" Text='<%# DataBinder.Eval(Container.DataItem, "FeatureTitle")%>' runat="server"></asp:TextBox> <div class="dvButton"> <asp:ImageButton ID="btnUpdate" runat="server" ImageUrl="/Images/ok_16x16.gif" AlternateText= "Update" CommandName="Update" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "FeatureID") %>' Width="12" Height="12" /> <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="/Images/delete_16x16.gif" AlternateText= "Cancel" CommandName="Cancel" Width="12" Height="12" CausesValidation="false" /> </div> </li> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="txtFeature" runat="server"></asp:TextBox> <div class="dvButton"> <asp:ImageButton ID="btnInsert" runat="server" ImageUrl="/Images/ok_16x16.gif" AlternateText= "Insert" CommandName="Insert" Width="12" Height="12" /> <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="/Images/delete_16x16.gif" AlternateText= "Cancel" CommandName="Cancel" Width="12" Height="12" CausesValidation="false" /> </div> </InsertItemTemplate> </asp:ListView> </div> </td> </tr> <tr> <td align="right"> <div id="dvButton" > <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Save" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID") %>' /> <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="Cancel" CommandName="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID") %>' /> </div> </td> </tr> </table> </ItemTemplate> </asp:ListView> Code Behind: protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { BindData(); } } private void BindData() { MyDataContext data = new MyDataContext(); var result = from itm in data.ItemLists where itm.ItemID == iItemID select new { itm.ItemID, itm.Description, FeatureList = itm.Features }; lvParent.DataSource = result; lvParent.DataBind(); } protected void lvChild_ItemEditing(object sender, ListViewEditEventArgs e) { ListView lvChild = sender as ListView; lvChild.EditIndex = e.NewEditIndex; lvChild.DataBind(); } Edit: protected void lvChild_ItemEditing(object sender, ListViewEditEventArgs e) { ListView lvChild = sender as ListView; lvChild.EditIndex = e.NewEditIndex; lvChild.DataBind(); } If I use "lvChild.DataBind()" in 'ItemEditing' event, the total list of child items goes away if I click 'edit' protected void lvChild_ItemEditing(object sender, ListViewEditEventArgs e) { ListView lvChild = sender as ListView; lvChild.EditIndex = e.NewEditIndex; } if I get rid of 'lvChild.Databind' in ItemEditing event, it goes to Edit mode after clicking the 'edit' button twice . And though it shows textbox control of EditItemTemplate, it appears as a blank textbox (does not bind existing value to edit).

    Read the article

  • Why can’t GridView extract child control’s values directly?

    - by SourceC
    Hello using Bind in a GridView control template enables the control to extract values from child controls in the template and pass them to the data source control. The data source control in turn performs the appropriate command for the database. For this reason, the Bind function is used inside the EditItemTemplate or InsertItemTemplate of a data-bound control. Why is Bind() needed to extract values and pass them to GridView. Why isn’t GridView able to extract child control’s values directly? thanx

    Read the article

  • DropDownList not updating value

    - by annelie
    Hello, I posted a question earlier but have another problem after making those changes. The previous thread can be found here: http://stackoverflow.com/questions/2700028/binding-a-dropdownlist-inside-a-detailsview Basically, I've got a dropdownlist that's dynamically populated with a list of regions. It selects the correct region when viewing the dropdown, but when I try to edit it changes the value to null. I think it might be because it doesn't know which field to update. Previously, when the dropdown list was hardcoded, I had SelectedValue='<%# Bind("region_id")%' set on the dropdown list, and when I updated it worked fine. However, I had to move the setting of the selected value into the code behind and now it just gets set to null every time I update. Here's the aspx code: <asp:DetailsView id="DetailsView1" runat="server" AutoGenerateRows="false" DataSourceID="myMySqlDataSrc" DataKeyNames="id" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateInsertButton="False" OnDataBound="DetailsView1_DataBound" > <Fields> <snip> <asp:TemplateField HeaderText="Region"> <ItemTemplate><%# Eval("region_name") %></ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="RegionDropdownList" runat="server"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> </Fields> </asp:DetailsView> And here's the code behind: protected void DetailsView1_DataBound(object sender, EventArgs e) { ArrayList regionsList = BPBusiness.getRegions(); if (DetailsView1.CurrentMode == DetailsViewMode.Edit) { DropDownList ddlRegions = (DropDownList)DetailsView1.FindControl("RegionDropdownList"); if (ddlRegions != null) { ddlRegions.DataSource = regionsList; ddlRegions.DataValueField = "Value"; ddlRegions.DataTextField = "Text"; ddlRegions.DataBind(); if (ddlRegions.Items.Contains(ddlRegions.Items.FindByValue(objBusiness.iRegionID.ToString()))) { ddlRegions.SelectedIndex = ddlRegions.Items.IndexOf(ddlRegions.Items.FindByValue(objBusiness.iRegionID.ToString())); } } } } EDIT: The database is MySql, and the update statement looks like this: myMySqlDataSrc.UpdateCommand = "UPDATE myTable SET business_name = ?, addr_line_1 = ?, addr_line_2 = ?, addr_line_3 = ?, postcode = ?, county = ?, town_city = ?, tl_url = ?, customer_id = ?, region_id = ?, description = ?, approval_status = ?, tl_user_name = ?, phone = ?, uploaders_own = ? WHERE id = ?"; Thanks, Annelie

    Read the article

  • Using User Controls in FormView templates.

    - by ProfK
    I find the repetition of sets of controls for each of the EditItemTemplate, InsertItemTemplate, and ItemTemplate templates of a FormView to be tedious and risky, in terms duplicating layout and code etc. I would much rather create a xxxDetails user control, and use this in each template, cutting layout and code location down to one location. However, this introduces several complexities for data binding scenarios. Are there any extablished patterns or practice guides for using user controls in these scenarios?

    Read the article

  • ASP.NET ObjectDataSource, change CommandName property of FromView Button

    - by Tone
    I have an ObjectDataSource that I'm using with a FormView, and it works fine, but i want to change one small thing. On the FormView the button that fires the update has the CommandName attribute set to "Update," but I would like to change that attribute to something other than "Update" - when I do change that attribute the update no longer works. The reason I want to do this is I have multiple FormViews on the same page and need to have multiple update buttons. Below is my code: FormView: <asp:FormView ID="fvGeneralInfo" runat="server" DataSourceID="objInstructorDetails" CssClass="Gridview" OnItemCommand="fvGeneralInfo_ItemCommand" DefaultMode="Edit"> <EditItemTemplate> <table> .... <tr> <td style="text-align:right;"> <asp:Label runat="server" ID="lblGeneralInfoMessage" Text="General Info updated successfully" Visible="false" /> </td> <td> <asp:Button runat="server" ID="btnUpdateGeneralInfo" ValidationGroup="UpdateGeneralInfo" Text="Update" CommandName="Update" /> <asp:Button runat="server" ID="btnCancelGeneralInfo" Text="Cancel" CommandName="CancelGeneralInfo" /> </td> </tr> </table> </EditItemTemplate> </asp:FormView> ObjectDataSource: <asp:ObjectDataSource ID="objInstructorDetails" runat="server" TypeName="AIMLibrary.BLL.Instructor" SelectMethod="GetInstructorDetails" InsertMethod="InsertInstructor" UpdateMethod="UpdateInstructor" OnInserting="objInstructorDetails_OnInserting" OnUpdating="objInstructorDetails_OnUpdating" > <SelectParameters> <asp:QueryStringParameter Name="InstructorId" QueryStringField="InstructorId" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="instructorId" Type="Int32" /> <asp:Parameter Name="firstName" Type="String" DefaultValue="" /> <asp:Parameter Name="middleName" Type="String" DefaultValue="" /> <asp:Parameter Name="lastName" Type="String" DefaultValue="" /> <asp:Parameter Name="phone" Type="String" DefaultValue="" /> <asp:Parameter Name="email" Type="String" DefaultValue="" /> <asp:Parameter Name="addressLine1" Type="String" DefaultValue="" /> <asp:Parameter Name="addressLine2" Type="String" DefaultValue="" /> <asp:Parameter Name="city" Type="String" DefaultValue="" /> <asp:Parameter Name="state" Type="String" DefaultValue="" /> <asp:Parameter Name="zip" Type="String" DefaultValue="" /> <asp:Parameter Name="abcBoardNumber" Type="String" DefaultValue="" /> </UpdateParameters> </asp:ObjectDataSource>

    Read the article

  • Can't Show image in gridview using templates

    - by n10i
    i am trying to load images from the northwind database (categories table, images that are stored in the database) into grid view control. But it dosenot seems to work. Plz! have a look... Default.aspx <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="NorthWindSQLExpressConnectionString" EnableModelValidation="True"> <Columns> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" /> <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" /> <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /> <asp:TemplateField HeaderText="Picture" SortExpression="Picture"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Picture") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl='<%# RetriveImage(Eval("CategoryID")) %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="NorthWindSQLExpressConnectionString" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindSQLExpressConnectionString %>" SelectCommand="SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Categories]"> </asp:SqlDataSource> </div> </form> [Partial] Default.aspx.cs protected string RetriveImage(object eval) { return ("ImageHandler.ashx?CategoryID=" + eval.ToString()); } [Partial] ImageHandler.ashx public void ProcessRequest(HttpContext context) { if (context.Request.QueryString == null) { } else { try { using (var sqlCon = new SqlConnection(conString)) { const string cmdString = "Select picture from Categories where CategoryID=@CategoryID"; using (var sqlCmd = new SqlCommand(cmdString, sqlCon)) { sqlCmd.Parameters.AddWithValue("@CategoryID", context.Request.QueryString["CategoryID"]); string trmp = sqlCmd.ToString(); sqlCon.Open(); using (var sqlDr = sqlCmd.ExecuteReader()) { sqlDr.Read(); context.Response.BinaryWrite((byte[])sqlDr["Picture"]); } } } } catch (Exception ex) { context.Response.Write(ex.Message); } } }

    Read the article

  • Binding navigation property to RadGrid while using EntityDataSource control

    - by Matrix
    I'm new to Entity Framework and I got stuck in an issue while trying to bind a navigation property (foreign key reference) to a dropdownlist. I have Telerik RadGrid control which gets the data using a EntityDataSource control. Here is the model description: Applications: AppId, AppName, ServerId Servers: ServerId, ServerName The Applicaitons.ServerId is a foreign key reference to Servers.ServerId. The RadGrid lists the applications and allows the user to insert/update/delete an application. I want to show the server names as a dropdownlist in edit mode which I'm not able to. . Here is my aspx code: <telerik:RadGrid ID="gridApplications" runat="server" Skin="Sunset" AllowAutomaticInserts="True" AllowAutomaticDeletes="True" AllowPaging="True" AllowAutomaticUpdates="True" AutoGenerateColumns="False" OnItemCreated="gridApplications_ItemCreated" DataSourceID="applicationsEntityDataSource" Width="50%" OnItemInserted="gridApplications_ItemInserted" OnItemUpdated="gridApplications_ItemUpdated" OnItemDeleted="gridApplications_ItemDeleted" GridLines="None"> <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="False" DataKeyNames="AppId" DataSourceID="applicationsEntityDataSource"> <RowIndicatorColumn> <HeaderStyle Width="20px" /> </RowIndicatorColumn> <ExpandCollapseColumn> <HeaderStyle Width="20px" /> </ExpandCollapseColumn> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderText="Edit" ItemStyle-Width="10%"> </telerik:GridEditCommandColumn> <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Are you sure you want to delete this application?" ConfirmTitle="Confirm Delete" ConfirmDialogType="Classic" ItemStyle-Width="10%" HeaderText="Delete"> </telerik:GridButtonColumn> <telerik:GridBoundColumn DataField="AppId" UniqueName="AppId" Visible="false" HeaderText="Application Id" ReadOnly="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="AppName" UniqueName="AppName" HeaderText="Application Name" MaxLength="30" ItemStyle-Width="40%"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn DataField="ServerId" UniqueName="ServerId" HeaderText="Server Hosted" EditFormColumnIndex="1"> <EditItemTemplate> <asp:DropDownList ID="ddlServerHosted" runat="server" DataTextField="Servers.ServerName" DataValueField="ServerId" Width="40%"> </asp:DropDownList> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> <EditFormSettings ColumnNumber="2" CaptionDataField="AppId" InsertCaption="Insert New Application" EditFormType="AutoGenerated"> <EditColumn InsertText="Insert record" EditText="Edit application id #:" EditFormColumnIndex="0" UpdateText="Application updated" UniqueName="InsertCommandColumn1" CancelText="Cancel insert" ButtonType="ImageButton"></EditColumn> <FormTableItemStyle Wrap="false" /> <FormTableStyle GridLines="Horizontal" CellPadding="2" CellSpacing="0" Height="110px" Width="110px" /> <FormTableAlternatingItemStyle Wrap="false" /> <FormStyle Width="100%" BackColor="#EEF2EA" /> <FormTableButtonRowStyle HorizontalAlign="Right" /> </EditFormSettings> </MasterTableView> </telerik:RadGrid> <asp:EntityDataSource ID="applicationsEntityDataSource" runat="server" ConnectionString="name=AnalyticsEntities" EnableDelete="True" EntityTypeFilter="Applications" EnableInsert="True" EnableUpdate="True" EntitySetName="Applications" DefaultContainerName="AnalyticsEntities" Include="Servers"> </asp:EntityDataSource> I tried another approach where I replaced the GridTemplateColumn with the following code <telerik:RadComboBox ID="RadComboBox1" DataSourceID="serversEntityDataSource" DataTextField="ServerName" DataValueField="ServerId" AppendDataBoundItems="true" runat="server" > <Items> <telerik:RadComboBoxItem /> </Items> and using a separate EntityDataSource control as follows: <asp:EntityDataSource ID="serversEntityDataSource" runat="server" ConnectionString="name=AnalyticsEntities" EnableDelete="True" EntityTypeFilter="Servers" EnableInsert="True" EnableUpdate="True" EntitySetName="Servers" DefaultContainerName="AnalyticsEntities"> </asp:EntityDataSource> but, I get the following error. Application cannot be inserted. Reason: Entities in 'AnalyticsEntities.Applications' participate in the 'FK_Servers_Applications' relationship. 0 related 'Servers' were found. 1 'Servers' is expected. My question is, how do you bind the navigation property and load the values in the DropDownList/RadComboBox control?

    Read the article

  • asp.net detailsview update method not getting new values

    - by Ali
    Hi all, I am binding a detailsview with objectdatasource which gets the select parameter from the querystring. The detailsview shows the desired record, but when I try to update it, my update method gets the old values for the record (and hence no update). here is my detailsview code: <asp:DetailsView ID="dvUsers" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataSourceID="odsUserDetails" onitemupdating="dvUsers_ItemUpdating"> <Fields> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" ReadOnly="true" /> <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" /> <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" /> <asp:BoundField DataField="Email" runat="server" HeaderText="Email" SortExpression="Email" /> <asp:BoundField DataField="IsActive" HeaderText="Is Active" SortExpression="IsActive" /> <asp:BoundField DataField="IsOnline" HeaderText="Is Online" SortExpression="IsOnline" ReadOnly="true" /> <asp:BoundField DataField="LastLoginDate" HeaderText="Last Login" SortExpression="LastLoginDate" ReadOnly="true" /> <asp:BoundField DataField="CreateDate" HeaderText="Member Since" SortExpression="CreateDate" ReadOnly="true" /> <asp:TemplateField HeaderText="Membership Ends" SortExpression="ExpiryDate"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ExpiryDate") %>'></asp:TextBox> <cc1:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox1"> </cc1:CalendarExtender> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ExpiryDate") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("ExpiryDate") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Fields> and here is the objectdatasource code: <asp:ObjectDataSource ID="odsUserDetails" runat="server" SelectMethod="GetAllUserDetailsByUserId" TypeName="QMS_BLL.Membership" UpdateMethod="UpdateUserForClient"> <UpdateParameters> <asp:Parameter Name="User_ID" Type="Int32" /> <asp:Parameter Name="firstName" Type="String" /> <asp:Parameter Name="lastName" Type="String" /> <asp:SessionParameter Name="updatedByUser" SessionField="userId" DefaultValue="1" /> <asp:Parameter Name="expiryDate" Type="DateTime" /> <asp:Parameter Name="Email" Type="String" /> <asp:Parameter Name="isActive" Type="String" /> </UpdateParameters> <SelectParameters> <asp:QueryStringParameter DefaultValue="1" Name="User_ID" QueryStringField="User_ID" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> Is the OnItemUpdating method still required when you have your custom BLL method called on insertevent? (which is being executed fine in my case but updating with the old values) or am I missing something else? Also I tried to provide an OnItemUpdating method and in there I tried to capture the contents of the textboxes (the new values). I got an exception: "Specified argument was out of the range of valid values. Parameter name: index" when I tried to do: TextBox txtFirstName = (TextBox)dvUsers.Rows[1].Cells[1].Controls[0]; Any help will be most appreciated.

    Read the article

  • Dynamic gridview columns event problem

    - by ropstah
    Hi, i have a GridView (selectable) in which I want to generate a dynamic GridView in a new row BELOW the selected row. I can add the row and gridview dynamically in the Gridview1 PreRender event. I need to use this event because: _OnDataBound is not called on every postback (same for _OnRowDataBound) _OnInit is not possible because the 'Inner table' for the Gridview is added after Init _OnLoad is not possible because the 'selected' row is not selected yet. I can add the columns to the dynamic GridView based on my ITemplate class. But now the button events won't fire.... Any suggestions? The dynamic adding of the gridview: Private Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender Dim g As GridView = sender g.DataBind() If g.SelectedRow IsNot Nothing AndAlso g.Controls.Count &gt; 0 Then Dim t As Table = g.Controls(0) Dim r As New GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal) Dim c As New TableCell Dim visibleColumnCount As Integer = 0 For Each d As DataControlField In g.Columns If d.Visible Then visibleColumnCount += 1 End If Next c.ColumnSpan = visibleColumnCount Dim ph As New PlaceHolder ph.Controls.Add(CreateStockGrid(g.SelectedDataKey.Value)) c.Controls.Add(ph) r.Cells.Add(c) t.Rows.AddAt(g.SelectedRow.RowIndex + 2, r) End If End Sub Private Function CreateStockGrid(ByVal PnmAutoKey As String) As GridView Dim col As Interfaces.esColumnMetadata Dim coll As New BLL.ViewStmCollection Dim entity As New BLL.ViewStm Dim query As BLL.ViewStmQuery = coll.Query Me._gridStock.AutoGenerateColumns = False Dim buttonf As New TemplateField() buttonf.ItemTemplate = New QuantityTemplateField(ListItemType.Item, "", "Button") buttonf.HeaderTemplate = New QuantityTemplateField(ListItemType.Header, "", "Button") buttonf.EditItemTemplate = New QuantityTemplateField(ListItemType.EditItem, "", "Button") Me._gridStock.Columns.Add(buttonf) For Each col In coll.es.Meta.Columns Dim headerf As New QuantityTemplateField(ListItemType.Header, col.PropertyName, col.Type.Name) Dim itemf As New QuantityTemplateField(ListItemType.Item, col.PropertyName, col.Type.Name) Dim editf As New QuantityTemplateField(ListItemType.EditItem, col.PropertyName, col.Type.Name) Dim f As New TemplateField() f.HeaderTemplate = headerf f.ItemTemplate = itemf f.EditItemTemplate = editf Me._gridStock.Columns.Add(f) Next query.Where(query.PnmAutoKey.Equal(PnmAutoKey)) coll.LoadAll() Me._gridStock.ID = "gvChild" Me._gridStock.DataSource = coll AddHandler Me._gridStock.RowCommand, AddressOf Me.gv_RowCommand Me._gridStock.DataBind() Return Me._gridStock End Function The ITemplate class: Public Class QuantityTemplateField : Implements ITemplate Private _itemType As ListItemType Private _fieldName As String Private _infoType As String Public Sub New(ByVal ItemType As ListItemType, ByVal FieldName As String, ByVal InfoType As String) Me._itemType = ItemType Me._fieldName = FieldName Me._infoType = InfoType End Sub Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn Select Case Me._itemType Case ListItemType.Header Dim l As New Literal l.Text = "&lt;b&gt;" & Me._fieldName & "</b>" container.Controls.Add(l) Case ListItemType.Item Select Case Me._infoType Case "Button" Dim ib As New Button() Dim eb As New Button() ib.ID = "InsertButton" eb.ID = "EditButton" ib.Text = "Insert" eb.Text = "Edit" ib.CommandName = "Edit" eb.CommandName = "Edit" AddHandler ib.Click, AddressOf Me.InsertButton_OnClick AddHandler eb.Click, AddressOf Me.EditButton_OnClick container.Controls.Add(ib) container.Controls.Add(eb) Case Else Dim l As New Label l.ID = Me._fieldName l.Text = "" AddHandler l.DataBinding, AddressOf Me.OnDataBinding container.Controls.Add(l) End Select Case ListItemType.EditItem Select Case Me._infoType Case "Button" Dim b As New Button b.ID = "UpdateButton" b.Text = "Update" b.CommandName = "Update" b.OnClientClick = "return confirm('Sure?')" container.Controls.Add(b) Case Else Dim t As New TextBox t.ID = Me._fieldName AddHandler t.DataBinding, AddressOf Me.OnDataBinding container.Controls.Add(t) End Select End Select End Sub Private Sub InsertButton_OnClick(ByVal sender As Object, ByVal e As EventArgs) Console.WriteLine("insert click") End Sub Private Sub EditButton_OnClick(ByVal sender As Object, ByVal e As EventArgs) Console.WriteLine("edit click") End Sub Private Sub OnDataBinding(ByVal sender As Object, ByVal e As EventArgs) Dim boundValue As Object = Nothing Dim ctrl As Control = sender Dim dataItemContainer As IDataItemContainer = ctrl.NamingContainer boundValue = DataBinder.Eval(dataItemContainer.DataItem, Me._fieldName) Select Case Me._itemType Case ListItemType.Item Dim fieldLiteral As Label = sender fieldLiteral.Text = boundValue.ToString() Case ListItemType.EditItem Dim fieldTextbox As TextBox = sender fieldTextbox.Text = boundValue.ToString() End Select End Sub End Class

    Read the article

  • I'm trying to handle the updates on 2 related tables in one DetailsView using Jquery and Linq, and h

    - by Ben Reisner
    Given two related tables (reports, report_fields) where there can be many report_fields entries for each reports entry, I need to allow the user to enter new report_fields, delete existing report_fields, and re-arrange the order. Currently I am using a DetailsView to handle the editing of the reports. I added some logic to handle report_fields, and currently it allows you to succesfully re-arrange the order, but i'm a little stumped as to the best way to add new items, or delete existing items. The basic logic I have is that each report_fields is represented by a . It has a description as the text, and a field for each field in the report_fields table. I use JQuery Sortable to allow the user to re-arrange the LIs. Abbreviated Create Table Statements:(foreign key constraint ignored for brevity) create table report( id integer primary key identity, reportname varchar(250) ) create table report_fields( id integer primary key identity, reportID integer, keyname integer, keyvalue integer, field_order integer ) My abbreviated markup: <asp:DetailsView ...> ... <asp:TemplateField HeaderText="Fields"> <EditItemTemplate> <ul class="MySortable"> <asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("report_fields") %>'> <ItemTemplate> <li> <%# Eval("keyname") %>: <%# Eval("keyvalue") %> <input type="hidden" name="keyname[]" value='<%# Eval("keyname") %>' /> <input type="hidden" name="keyvalue[]" value='<%# Eval("keyvalue") %>' /> </li> </ItemTemplate> </asp:Repeater> </ul> </EditItemTemplate> </asp:TemplateField> </asp:DetailsView> <asp:LinqDataSource ID="LinqDataSource2" onupdating="LinqDataSource2_Updating" table=reports ... /> $(function() { $(".MySortable").sortable({ placeholder: 'MySortable-highlight' }).disableSelection(); }); Code Behind Class: public partial class Administration_AddEditReport protected void LinqDataSource2_Updating(object sender, LinqDataSourceUpdateEventArgs e) { report r = (report)e.NewObject; MyDataContext dc = new MyDataContext(); var fields = from f in dc.report_fields where f.reportID == r.id select f; dc.report_fields.DeleteAllOnSubmit(fields); NameValueCollection nvc = Request.Params; string[] keyname = nvc["keyname[]"].Split(','); string[] keyvalue = nvc["keyvalue[]"].Split(','); for (int i = 0; i < keyname.Length; i++) { report_field rf = new report_field(); rf.reportID = r.id; rf.keyname = keyname[i]; rf.keyvalue = keyvalue[i]; rf.field_order = i; dc.report_fields.InsertOnSubmit(rf); } dc.SubmitChanges(); } }

    Read the article

< Previous Page | 1 2 3  | Next Page >