how to make dropdownlist (templatefield) on datagrid editable just when edit button clicked..?

 I have a dropdownlist as a templatefield on a gridview using ASP.NET 2005 (VB).. I want this dropdownlist's enabled property is set false when the grid is loaded, but I want it becomes enabled when I click Edit button on the grid (Edit button is a commandfield)..

 How do I do it? If anyone gets the informations, please let me know..

Or is there a way of showing the value on the grid by Label templatefield first, and when Edit button is click, show the Dropdownlist templatefield, and the colums where the Label templatefield is placed set false for the Visible property?

 Thank you very much.


 

0
ch
9/19/2007 4:37:24 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
725 Views

Similar Articles

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

Change your TemplateField into this:

    <asp:TemplateField>
     <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
     </ItemTemplate>
     <EditItemTemplate>
      <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
       DataTextField="Title" DataValueField="Title">
      </asp:DropDownList>
     </EditItemTemplate>
    </asp:TemplateField>
and put this in code-behind:
 Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
  Dim ddl As DropDownList = CType(GridView1.Rows(e.RowIndex).FindControl("DropDownList1"), DropDownList)
  e.NewValues("Title") = ddl.SelectedValue
 End Sub
and just change "Title" with your column name (in all 4 places).

0
kipo
9/19/2007 9:51:14 AM

Hi.

Thank you very much for your answers..

I've found the answer. I mean, I just use a Label for the ItemTemplate on the templateField, and a DropdownList for the EditItemTemplate..

That's all my problem..Big Smile I don't have very deep knowledge in ASP.NET, so I apologize if sometimes my questions are very simple ones..

Thank you very much again..

- ch -
 

0
ch
9/21/2007 3:46:54 AM
Reply:

Similar Artilces:

Inline Editing in DataGrid without actually having to click on an edit button
Is it possible to allow inline editing in a DataGrid for each row without having to click an edit button for each row? Basically we have users who have to go through thousands of records and edit and they don't watn to have to keep clicking the edit button in order to invoke the inline editing feature of a DataGrid.basically they just want to give focus to each row with like a tab on the keyboard and be able to just tab their way through to edit each row's data.When is Microsoft going to get rid of VB.NET! Hi:   From your description I think you can just put a TextBox and a &...

Editable DataGrid --> DropDown List --> How to retreive SelectedItem when clicking Edit button
<asp:TemplateColumn HeaderText="V.Type" SortExpression="vehicle_type" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="left"> <ItemTemplate> <%#DataBinder.Eval(Container.DataItem , "vehicle_type")%> </ItemTemplate> <EditItemTemplate> <asp:DropDownList id="dd_vehicle_type" runat="server"> <asp:ListItem><%#DataBinder.Eval(Container.DataItem , "vehicle_type")%></asp:ListItem> <asp:ListItem>Sedan</asp:ListI...

how to get first column value after clicking edit button in datagrid
 Hi, I have a small problem while working with datagrid. My code looks as follows:public void dgrdList_Command(object s, DataGridCommandEventArgs e){    switch (e.CommandName){        case "edit":                EditForm((int)dgrdList.DataKeys[e.Item.ItemIndex]);            break;        case "delete":           ...

Return in a Edit Item Template text box to cause the Edit Command button to click in a DataGrid
Hello Everyone I have a DataGrid with ItemTemplates.  What the client wants is to be able to hit return in the edit item template's text box, and as a result have the Edit Command Save button clicked. Doing a search I came across several discussions of this topic that indicated that one could do this using JavaScript, but I'm unclear about how to go about this; I'm guessing that I can trap the key press in the box and cause a postback if it's the return key but don't know what event I'm looking for. Suggestions?   Thanks in advance! I am assuming that there's only one save b...

Datagrid Edit without Edit button
I have a unique situation where a user wants to edit a large volume of data without have to select edit at each row (much like a spreadsheet). I have created a DG and added a new column for the "new" value but have not found a way to open the entire grid at one time. Suggestions.......

Making editable datagrid in which all rows are editable
I find Scott Mitchel article http://aspnet.4guysfromrolla.com/demos/dgExample35.aspx Which displays all the rows in editable mode. Now is there any way to know only that which rows have been changed. I mean if I change only one row in the datagrid so I only need to get that one row. Since I am sending all in the database and I dont want to send all the rows back to the database. this will be bad for performance. any ideas ??? HighOnCodingWanna get high! Yes, excellent article that one...The idea of that demo was to illustrate how you can edit ALL the data in a datagrid; s...

Make id field in editable datagrid not editable.
I've got an editable datagrid that lets users add, update, and delete records. Only thing I'm having problems with is that the id field is showing up as editable as well. And I don't want this to be editable. It is an auto-identity type field in our SQL Server db. Can anyone show me how to make this not editable and also how to not let a user enter any id when adding a new record. This is a lot of code. Sorry! Thanks for any help. <%@ Page Language="VB" Debug="true" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.SqlClient" %> <%@ Register TagPrefix="IAR" TagName="Header" Src="../_header_Lvl2.ascx" %> <%@ Register TagPrefix="IAR" TagName="Footer" Src="../_footer.ascx" %> <script runat="server"> ' TODO: update the ConnectionString and Command values Dim SelectCommand As String = "SELECT * from Staff" Dim ConnectionString As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim isEditing As Boolean = False Sub Page_Load(Sender As Object, E As EventArgs) If Not Page.IsPostBack Then ' Databind the data grid on the first request only ' (on postback, bind only in editing, paging and sorting commands) BindGrid() End If ...

setting a password on datagrid (editable) edit button
is it possible to set a password on the edit and/or delete for an editable datagrid ? if so how would I go about doing it ? I want to be able to allow certian people to edit/delete only a specific row in the datagrid using a password or their user.identity. Any advice, help or tutorials would be greatly appriciated you should use forms authentication - you'll be seeking this functionality throughout many applications in the future. you can then make the edit buttons visible/invisible based on the users roles....

can we find control of itemtemplate in updatecommandeventargs of datagrid after clicking edit button in the datagrid?
hi im having a editable datagrid here in one column of template field im having a label control in itemtemplate and a textbox control in edititemtemplate.now i want to find the label control in update command eventargs ...is this possible here im able to find the control of edititemplate but im unable to find the control of itemplate .pavankumar In any event, you can find controls in itemtemplate. for(int vLoop=0 ; vLoop<gv1.rows.count ; vLoop++) {     Label lbl = (Label)gv1.rows[vLoop].findcontrol("lblID"); }Give a man a fish and you feed him for a day. Te...

How to edit DataGrid without using Edit,updatebutton buttons?
Hi,   I want to edit and update edited values in the datagrid without using EDIT button.   My requirement is, when i click the particular column[cell, not header] only that column has to display textbox.   OR   When i click the one cell, total column has to displays taxtboxes..   Looking for someone help.   Pradeep Kumar Bura...

editable gridview when user click external edit button
Hi Friend, I have gridview with columns id, fname, lname and email. I have bound the gridview from the table. Now my requirement is: I need to have editable gridview with edit button external to gridview. I can do it, if the edit button is internal to gridview. But I want to achieve editable gridview when user click external edit button. Is it possible or any other control that have this future?  Thanks, FarooqMark as answer if this post helpfull to you.Don't be afraid to be wrong; otherwise you'll never be right.  Do you want to make a certain row editable or t...

Get some extra data on EDIT keypress of editable datagrid
G'day, I have an editable datagrid with a EDIT PushButton. When I push EDIT I'd like to capture the value of the first column of the datagrid (I want to present some additional info about this particular item at the same time as doing the edit). eg: Sub Edit(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs) dgItems.EditItemIndex = E.Item.ItemIndex bindData() Dim itemID As Integer = ??? ' what is the syntax for this step here if the first column is 'itemID' ? showImages(itemID) 'will load all ...

Calling the Edit command instead of clicking the Edit button
Hi, Can I have a datagrid that can click any where in the row to call the Edit Command instead of clicking the Edit Button? Cheers. PLLMS Hi, I wrote a receipt with similar subject in the Cookbook, where you can set the EditItemIndex instead of SelectedIndex as shown in the receipt: Implementing Support for DoubleClicks in a DataGrid Regards Thanks, Colt. My code can now call the Edit Command where ever i click in a row. But i have another question. I have a number of columns on my datagrid. Am I able to get the column (cell) number on which User clicks...

VB.NET
I have a DataGrid (see code at end of my question) with several dropdownlist controls within TemplateColumns for Editing.  For the first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like to populate ddlMedicationName based on the selecteditem of ddlMedType, but I don't know how to reference this. Thank you for saving me from confusion!!!! Here is my DataGrid code: NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!! ================== <asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateCommand="dgMeds_UpdateRow"     OnCancelCommand="dgMeds_CancelRow" AutoGenerateColumns="False" Visible="False">     <Columns>         <asp:BoundColumn DataField="medid" ReadOnly="True" HeaderText="MEDID"></asp:BoundColumn>         <asp:BoundColumn DataField="subjid" ReadOnly="True" HeaderText="Subject ID"></asp:BoundColumn>         <asp:BoundColumn DataField="visitnum" ReadOnly="True" HeaderText="Visit #"></asp:BoundColumn>         <asp:TemplateColumn HeaderText="Medication Type">             <ItemTemplate>                 <%# DataBinder.Eval(Container.DataItem, "medt...

Edit but no edit
I've Created a custom module and reuse the survey.dnn file to help with the install here it is. <?xml version="1.0" encoding="utf-8" ?> <dotnetnuke version="2.0" type="Module"> <folders> <folder> <name>CompanyName - Photos</name> <description>Photos allows you to add photo albums</description> <version>01.00.00</version> <modules> <module> <friendlyname>CompanyName - Photos</friendlyname> <controls> <c...

To edit or no to edit
Jon, Can I edit, whatever I've written so far, so that it doesn't look like I wrote utterly crap?-) -- Pieter "Linux is like living in a teepee. No Windows, no Gates, Apache in house." -- Usenet signature Pieter Zijlstra wrote: > Jon, > > Can I edit, whatever I've written so far, so that it doesn't look like > I wrote utterly crap?-) Oh boy, the edit button vanished from the web-forum ... ;-) -- Pieter "Humor is also a way of saying something serious." -- T. S. Eliot (1888 - 1965) Pieter Zijlstra wrote: ...

Cant get new/edited values from cells when editing a datagrid ...
I'm having some trouble with editing the data in a datagrid.   When i go into edit mode and change to values, they revert to the original ones as soon as the update command is run.  My update command runs a stored proc on a sql server database and i have checked that it is working by giving it fixed strings as the parameters.  It works fine and updates the values as required.   The problem is, when i try to feed in the cell values to the stored proc, it just saves the original values that were in the cells and not the values that i updated.   Why ...

Populating a dropdownlist on the edit click of my datagrid
I want to populate a dropdownlist within the edit template of my datagrid when the user selects the edit link.  The idea is they select the edit link, I populate the relevant listboxes, they select and click update.  I get an error onddlCountry.Items.Add(item); saying no object reference is available.  I figure its maybe because the dropdown hasnt yet been created?  Any ways in which I can overcome this???<code> private void dgdUsersWards_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { dgdUsersWards.EditItemIndex = e.Item.ItemIn...

Editable/Not Editable
Hello All, I have some webform(.aspx page) in which i have some controls (for input) and i would like to make that screen editable/not editable based on some condition. how can i do that.  the whole intent is user can read the information but can't change.  shiva kumar If you want to make the controls editable/non-editable, you can set their ReadOnly property to true or false accordingly. What exactly do you imply by making the screen editable/non-editable?Thanks,MaxLet Me Google That For You! i mean to say i would like to show the current values but user should not modify them. ReadOnly property is the way to go...Thanks,MaxLet Me Google That For You! Thanks bullpit. You can do it with javascript:   document.getElementById('TextBox1').readOnly = true;  Hope this helps!  Don't forget to mark the most helpful post(s) as Answer for the sake of future readers.  Thanks!Josh Stodola ← Come check out my blog!...

Problem getting a Datagrid to allow users to edit it...(in line editing)
Hi, In my DNN custom module I have three panels with various controls on them. If a user clicks the "edit database" button...it makes all these panels disappear and one appear. That panel has a datagrid on it. My goal is to allow users to manipulate the database information using the datagrid. The datagrid is bound to a dataset which is pulled from the database and the data displays fine. I tried adding a button column to the datagrid (I'm using Visual Studio) and it puts a nice "edit" button to the left of every row in the database. Very nice. My understanding ...

Cannot get value of DropDownList in DataGrid. edit mode.
Hello,  I have a DataGrid on a ASPX page. This datagrid contains a drop down list which is shown when Edit Mode is enabled. The DDL contains items for student grades (A,B,C....). Each item is entered manually in the HTML part. Here is the datagrid code fragment from the HTML page.   1 <asp:DataGrid ID="dgGrades" runat="server" Font-Names="Tahoma" Font-Size="XX-Small" CellPadding="4" 2 3 HeaderStyle-BackColor="Black" HeaderStyle-ForeColor="White" HeaderStyle-HorizontalAlign="Center" 4 5 HeaderStyle-Font-Bold="True" AutoGenerateColumns="False" BackColor="White" Width="100%" HeaderStyle-Font-Name="Tahoma" 6 7 BorderStyle="None" OnEditCommand="dgGrades_Edit" OnUpdateCommand="dgGrades_Update" OnItemDataBound=" DG_ItemDataBound"> 8 9 10 <Columns> 11 12 <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" 13 14 UpdateText="Update" HeaderStyle-Width=20 /> 15 16 17 18 <asp:TemplateColumn HeaderText="Grade ID" Visible =false> 19 20 <HeaderStyle HorizontalAlign="Center" width =60></HeaderStyle> 21 22 <ItemStyle HorizontalAlign="Center"></ItemStyle> 23 24 <ItemTemplate> 25 26 <%#DataBinder.Eval(Container.DataItem, "GradeID")%> 27 28 </ItemTemplate> 29 30 </asp:TemplateColumn> 31 32 33 34 ...

Adding an editable row to a datagrid on button click
Hi all, I have been trying to add an editable row to a datagrid on a button click. I have written the following code. private void Button1_Click(object sender, System.EventArgs e) {string strQry; strQry = "select [E-MailAddress], [E-MailName], [E-MailLeachWeekly], [E-MailRednWeekly], [E-MailServWeekly], [E-MailMonthly] from tblMailDistributionList"; //connectin stringSqlConnection conBridgingRegister = new SqlConnection(); conBridgingRegister.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];SqlCommand myCommand = new SqlCommand(strQry,conBr...

How to switch a entire gridview1 into edit mode instead of clicking the edit button on each row?
Hello, I have a gridview1 that opens up via a sqldatasource and to edit each field, I have to manually click edit on each row.  Please suggest a way to switch the entire gridview1 into edit mode after the page opens.  Thank you in advance,  ptown check out this sample: http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=gvfullyeditableDavid WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one control!Cale...

Setting focus to first editable column after clicking the "Edit" button
I have a basic Gridview control in my form and it allows editing.  When the user clicks the "Edit" button it would be nice if the focus was in the first editable text box.  This seems like a pretty standard thing to do although I can't seem to figure out how.  Anyone have ideas?   here u go;        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)        {            GridViewRow row = GridView1.Rows[e.NewEditIndex];            TextBox txt = row.FindControl("TextBox1");            txt.Focus();        } Raghu(MCSD.NET, MCAD.NET, MCDBA)[Don't forget to click on Mark as answer on the post that helped you ] rmaiya, that's not working for some reason; The FindControl does not 'find' the controI. I excerpted my code, maybe you can help me further.  Thanks<asp:TemplateField HeaderText="Group Name" SortExpression="GROUP_NM"><EditItemTemplate><asp:TextBox ID="txtGroupName" runat="server" Text='<%# Bind("GROUP_NM") %>'></asp:TextBox></EditItemTemplate>     protected void GridView1_RowEditing(object sender, GridView...

Web resources about - how to make dropdownlist (templatefield) on datagrid editable just when edit button clicked..? - asp.net.getting-started

ERROR: “Index was out of range” when Accessing the DataKeys Collection in a Paged GridView
... While working on a legacy ASP.NET WebForms application I stumbled into the following error: I had a paged GridView with a LinkButton in a TemplateField ...

Scott On Writing.NET
... While working on a legacy ASP.NET WebForms application I stumbled into the following error: I had a paged GridView with a LinkButton in a TemplateField ...

Resources last updated: 3/14/2016 10:23:28 PM