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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to disable fields in a GridView when you change the listbox options?

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
 Hi all I am trying to apply the same logic I applied to a FormView. Here is what I do:I have a DropDownListBox as one of my FormView fields and when I choose a specific option the fields inside my FormView are enabled/disabled according to the options chosen. Well I havent been able to apply that concept to a GridView. Here is my code to the FormView:protected void ItemFormView_DataBound(object sender, EventArgs e) { DropDownList ddlConfigType = ItemFormView.FindControl("ddlConfigTypes") as DropDownList; if (ddlConfigType != null) { if (ItemFormView.CurrentMode == FormViewMode.Edit) { DisableNAFields_EditMode(ddlConfigType.SelectedItem.Text); } } }private void DisableNAFields_EditMode(string configType) { TextBox txtboxScope = ItemFormView.FindControl("txtboxScope") as TextBox; if (configType == "registry") { txtboxScope.Enabled = false; } } Is there a GridView mode enumeration? How do I achieve the same goal? Thank you

View Complete Post

More Related Resource Links

ListBox tricky to set in a DataGrid/GridView

Listboxes are very tricky to set selected items in grid - there is no real nice way to do it. It would have been great if Microsoft included a property that accepts an array or comma separated values - or anything! But they only allow each item in the list to be selected individually. The way to do this in a grid is a bit messy, but it is fairly simple to implement. When a row is created (as per the event), select the items of the listbox as per the datagrid source data:

LINQ with GridView and edit fields


My project includes a grid view which displays information of inventory items (Assets), data is quried from AssetTable. The GridView has a command field to allow editing, below is a description of the tables and how data is displayed


BuildingTable: (BuildingID, BuildingName)

AssetTable: (BuildingID,..,....,....)


ItemTemplate: Using a LINQ query I join the two table and displays in a label control a string which includes BuildingID and BuildingName (5 North Building)

 EditItemTemplate: Using a LINQ query I populate a DropDownList with strings of BuildingID and BuildingName same as above.
Here  issue which I need to resolve:
1.  ItemTemplate display the correct information (BuildingID BuildingName) but when I switch to EditItemTemplate the pair that is 
displayed is the first one on the list, how do I make is scroll to the item which was displayed in the label ?
<asp:CommandField ShowEditButton="True" >
                    <ControlStyle Wi

Disable check box in a gridview does not working



I have a check box in a template field in a gridview.

Based on some condition, I want those check boxs to  be enable and disable.

I am trying the below code but does working..

 protected void GVstudents_RowDataBound(object sender, GridViewRowEventArgs e)
              if (e.Row.RowType == DataControlRowType.DataRow)
                    string studentID = GVstudents.DataKeys[0].Value.ToString();
                    int stdID = Convert.ToInt32(studentID);
                    int schID = profile.getSchoolIDByStudentID(stdID);
                    int tchrID = profile.getTeacherIDByStudentID(stdID);

                    if (patti.chkIsTeacherPaid(stdID, schID, tchrID))
                        CheckBox cb = (CheckBox)e.Row.FindControl("chkTeacherPayment");
                        cb.Enabled = false;
                        cb.Checked = true;


any help??

Change data on gridview bind


Hi there,

Simple little problem. i have a gridview that shows products assigned to a customers job. They are displayed in exVAT prices. To make it easier i want to show the inc VAT prices. How can i add VAT to 1 column in this table?

Can't change Gridview row colors or styles in the DataBound event


I was highlighting certain rows in my gridview using code like this in the DataBound event:

        if (e.Row.RowType == DataControlRowType.DataRow)
            int vendorCheck = 0;
            //TODO make this shorter
            if (DataBinder.Eval(e.Row.DataItem, "vendorId") != System.DBNull.Value)

how do i use javascript to change values of controls inside a gridview

i have 2 labels (lblRate,lblTotal) and a textbox (txtQuantity) in a itemtemplate of a gridview.I want to calculate the products of rate and quantity and show it in Total as the textbox loses focus...i cant use textchanged because i dont want the page to postback.How do i use javascript to achieve this??Please Help Urgently....<asp:TemplateField HeaderText="Rate">                <ItemTemplate>                    <asp:Label ID="lblRate" runat="server" Text='<%# Eval("Rate") %>' />                </ItemTemplate>            </asp:TemplateField> <asp:TemplateField HeaderText="Quantity">                <ItemTemplate>                    <asp:TextBox ID="txtQty" runat="server" />                </ItemTemplate>&

Change database fields automatically according to date

Hi, I'm currently developing a software application for my client. Part of the project is to keep track of his stock's shipping status. The client must insert the stock's pick-up date, expected time of departure (ETD) and expected time of arrival (ETA). The stocks will be called out using Grid View and the status, being one of the keys of the database, will be shown. Before the current date reaches pick-up date, the status must show "in warehouse", and after the current date reaches pick-up date and is before ETD, status must show that its "on the way to the port", and after ETD and before ETA, "in freight", and finally after ETA, "arrived". What datatype should I use for the database and where should I program it so that it changes automatically accordingly ?

How can I change the SelectedIndex on a listbox when another listbox is doubleclicked?

Here is my xaml. <     StackPanel>       <ListBox x:Name="List1">       <ListBoxItem>Part 1</ListBoxItem>       <ListBoxItem>Part 2</ListBoxItem>       <ListBoxItem>Part 3</ListBoxItem>       <ListBoxItem>Part 4</ListBoxItem>       <ListBox.Triggers>       <EventTrigger RoutedEvent="ListBox.MouseDoubleClick">       <BeginStoryboard>       <Storyboard Duration="00:00:00">       <Int32Animation Storyboard.TargetName="List2" Storyboard.TargetProperty="SelectedIndex" From="-1" To="0" Duration="00:00:00" FillBehavior="HoldEnd"></Int32Animation>       </Storyboard>       </BeginStoryboard>       </EventTrigger>       </ListBox.Triggers>       </ListBox>       <ListBox x:Name="List2">       <ListBoxItem>Section A</ListBoxItem>       <ListBoxItem>Section B</ListBoxItem>

Trap Selected Index change event of listbox using Javascript.

Hi All, This is reagarding listbox selection. I have a list box with multi select option. I want to trap the selected index change event of Listbox through javascript. Item of list box can be selected using Click of mouse and also the keyboard up down key with shift. I tried onclick event to bind the javascript function. It works fine if I select by mouse, but it doesen't work for up/down key of keyboard. Thanks, Naveen

Using UserName to enable disable access to InfoPath form fields

Hi Everyone, I have created a browser enable form in InfoPath and restrict certain fields depending on the official logged on User Name. Now this works most of the time but my problem has to do with the "case" of User Names for some of the site users. In most cases the User Name is an exact match but for some reason, some user's names are reported by SharePoint (the Welcome at top of screen) with some parts captilized. Example - my hidden filed on the form reports my user name as xrs_master but the Welcome up top says XRS_Master - and the fields act as though I am not the correct user and won't enable. On the other hand there are users who's user name matches the case exactly and all works fine. Why is SharePoint reporting the user name differently? And if this is the reason they don't match, how do I fix it? Any Ideas? Many thanks in advance for help!

disable autopostback of checkbox inside of GridView during SelectedIndexChanged of ListView

Hi, I hope my question is clear: I have a checkbox placed inside a gridview: <GridView><asp:TemplateField HeaderText="Driver">   <ItemTemplate>       <asp:CheckBox ID="CheckBoxDriver" AutoPostBack="true" OnCheckedChanged="GridView_Persons_SelectedIndexChanged" ValidationGroup='<%# Eval("ID") + "-" +((GridViewRow)Container).RowIndex %>' CssClass="CXDriver" runat="server" Checked='false' />   </ItemTemplate>       </GridView> For example: A listViewItem 1 has 3 drivers are checked, A listViewItem 2 has 2 drivers are checked. Therefore, if changing the selectedIndex of the list, the checkbox indexChanged event will be fired. How could I disable the autopostback of the checkbox during the listview item changed. Thanks in advance

Gridview Textbox Value Change

Hi,In my gridview i have productName(Dropdownlist),Description, Quantity, Price,Total and out side gridview i have textboxes like total, tax, discount and GrandTotal. When i select the product it will bind the price and description.  I will enter Quantity value in the quantity column then it will calculate with the price and display the total in the total column.  Where the total column is readonly when the total displayed it will reflect to Total adn grand total textboxes wich is outside of the gridview.  I am able to calculate the total but i am not able to bind the changed value to those text boxes.  when more than one products then it will calculate sum of total column and bind to the total, grand total textboxes.  How can get the total please advise me.Thanks & Regards,Jeevan.

Drop Down Listbox SelectedIndexChanged Event not firing when I programmatically change selection

I have two drop down listboxes (DDL1 and DDL2).  When DDL1 has an index change, DDL2 then has a refresh of list items based off SQL Server SELECT from a table.  The database isn't the problem.  Everything works perfectly when the user selects a new item manually from DDL1.But in my code, I save the user data from the selection of DDL1 in a separate table.  And then upon rendering of the page (Page_PreRenderComplete), I do a SelectedIndex assignment of the value of what's saved in the db table.  That works just fine, it selects the DDL1 item, but DDL2 is unaffected, as if DDL1's SelectedIndexChanged event isn't called like it would be if manually changed.  How can I get around this?Thanks in advance. :)

How to test mode change in gridview

Hi, When i run the following code i get an error when gridview changes mode to Edit.  stating that you can't change string to decimal! To get around the occurance i want to disable code when in Edit mode or resolve another way?  GridView1_RowDataBoundFor Each row As GridViewRow In GridView1.Rows            Dim cell As TableCell = row.Cells(7)            Dim invoicetotal As Decimal = CDec(cell.Text)   Thanks

how to change gridview edit/delete name?

I have a gridview and in my code behind i have added the edit/update functions like below now how can i change the name of edit/delete which automatically comes ?  <asp:GridView ID="friendListGridview" runat="server" CellPadding="4"          ForeColor="#333333" GridLines="None"         AllowPaging="true" AutoGenerateColumns="false" Width="80%"  AutoGenerateEditButton="True" DataKeyNames="id"         AutoGenerateDeleteButton="True"     >        <Columns>          <asp:TemplateField                 ItemStyle-HorizontalAlign="Center" HeaderText="<%$ Resources:default, friendList %>"  >                <ItemTemplate>                    <%# Eval("ListName") %>             &nbs

Image to appear in gridview if two other gridview fields meet condition

Hi all-I'm populating a gridview with this query:Dim DataForGridview = (From p In Products _                        Join a In customerCategoryA On p.productID Equals a.productID _                        Join b In customerCategoryB On p.productID Equals b.productID _                        Select New With _                                { _                                .Product = p.product, _                            &

disable a single intem in dropdownlist or stop the ddl change event for a single item


hello guys,

I am trying something apart of my boundries, is there any way to disable a single intem in dropdownlist or stop the ddl change event for a single item.

any feadback would be appriciable.

Thanks and Regards

Inderjeet Singh Khalsa

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

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