473,671 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid EditItemTemplat e-- how to retrieve a DropDownList validator?

Hi everyone,

I have a DataGrid with several TemplateColumns . One of these columns has an
EditItemTemplat e that contains an ASP.Net DropDownList. I'm catching this
DropDownList's SelectedIndexCh anged event.

I also have another TemplateColumn, with a RequiredFieldVa lidator that
validates a TextBox in the column. It all looks like this, in broad
strokes:

<TemplateColumn >
<EditItemTempla te>
<asp:DropDownLi st OnSelectedIndex Changed="some method">
</asp:DropDownLis t>
</EditItemTemplat e>
</TemplateColumn>
<TemplateColumn >
<EditItemTempla te>
<asp:TextBox id="textbox1">
</asp:TextBox>
<asp:RequiredFi eldValidator ControlToValida te="textbox1">
</asp:RequiredFie ldValidator>
</EditItemTemplat e>
</TemplateColumn>

When I'm in the method that catches the SelectedIndexCh anged event, can I
somehow retrieve the RequiredFieldVa lidator and set its properties? I've
been noodling with FindControl() in various incarnations but haven't found
the right mix yet. Any help or snippets are appreciated.

Thanks!
Apr 11 '07 #1
2 7310
Hi Steve,

I created an example to show you how to do it:

-- beging aspx code --

<script runat="server">

protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}

private void BindData()
{
dg.DataSource = new int[7];
dg.DataBind();
}

protected void DropDownList1_S electedIndexCha nged(object sender, EventArgs e)
{
int index = dg.EditItemInde x;
if (index >= 0)
{
DataGridItem item = dg.Items[index];

RequiredFieldVa lidator validator = (RequiredFieldV alidator)
item.FindContro l("rfv");
TextBox textBox = (TextBox) item.FindContro l("textBox1") ;
}
}
protected void dg_EditCommand( object source, DataGridCommand EventArgs e)
{
((DataGrid) source).EditIte mIndex = e.Item.ItemInde x;
BindData();
}
</script>

<asp:DataGrid runat="server" ID="dg" AutoGenerateCol umns="false"
OnEditCommand=" dg_EditCommand" >
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
column1
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st runat="server" ID="ddl"
OnSelectedIndex Changed="DropDo wnList1_Selecte dIndexChanged"
AutoPostBack="t rue">
<asp:ListItem Text="1" />
<asp:ListItem Text="2" />
<asp:ListItem Text="3" />
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<ItemTemplate >
column2
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox ID="textbox1" runat="server">
</asp:TextBox>
<asp:RequiredFi eldValidator ControlToValida te="textbox1" runat="server"
ID="rfv">
</asp:RequiredFie ldValidator>
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:ButtonColu mn CommandName="Ed it" Text="Edit" />
</Columns>
</asp:DataGrid>

-- end aspx code --

hope this helps

Milosz
"Steve Hershoff" wrote:
Hi everyone,

I have a DataGrid with several TemplateColumns . One of these columns has an
EditItemTemplat e that contains an ASP.Net DropDownList. I'm catching this
DropDownList's SelectedIndexCh anged event.

I also have another TemplateColumn, with a RequiredFieldVa lidator that
validates a TextBox in the column. It all looks like this, in broad
strokes:

<TemplateColumn >
<EditItemTempla te>
<asp:DropDownLi st OnSelectedIndex Changed="some method">
</asp:DropDownLis t>
</EditItemTemplat e>
</TemplateColumn>
<TemplateColumn >
<EditItemTempla te>
<asp:TextBox id="textbox1">
</asp:TextBox>
<asp:RequiredFi eldValidator ControlToValida te="textbox1">
</asp:RequiredFie ldValidator>
</EditItemTemplat e>
</TemplateColumn>

When I'm in the method that catches the SelectedIndexCh anged event, can I
somehow retrieve the RequiredFieldVa lidator and set its properties? I've
been noodling with FindControl() in various incarnations but haven't found
the right mix yet. Any help or snippets are appreciated.

Thanks!
Apr 11 '07 #2
Thanks very much Milosz. This looks like just what I need.

-Steve
Apr 11 '07 #3

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

Similar topics

0
399
by: Kins | last post by:
Hi, In web application, I use listbox in the EditItemTemplate in the Datagrid. But I cannot load data from the database to the Listbox. Is it possible ? Thx a lot regards, Kin
6
2902
by: Assimalyst | last post by:
Hi, I'm attempting to write a piece of code that acts as a client side validator for all drop down lists on a webform, giving an error if the SelectedIndex = 0. Here is what i have:
0
1196
by: Trevor Hartman | last post by:
Hi, I'm using an EditItemTemplate on my datagrid for a date column in the DB. How would I go about using EditItemTemplate to split the date into three drop downs for day / month / year? Thanks - Trevor
0
1142
by: Jeff Reed | last post by:
I have this in my coding for a DataGrid: <EditItemTemplate> <asp:DropDownList id="eCategoryList" runat="server" CssClass="selectBoxSmall" SelectedIndex='<%# DataBinder.Eval(Container.DataItem), "Category_FK"%>' DataValueField="Category_PK" DataTextField="Category" DataSource="<%#eCATdv%>"> </asp:DropDownList> </EditItemTemplate>
7
4212
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now the first item in the dropdown is always displayed. Template Code: <asp:TemplateColumn HeaderText="DropDown"> <ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval
1
1313
by: Mohamed Zaki | last post by:
Dear All, I've a datagrid in its footer i added a drop down list and some text boxes and a link button to add new records in the database, however i populate the dropdown list in the ItemDataBind, when i click over the linkbutton i got the dropdown list populated again and the selected item is lost. Please help. Regards,
3
1808
by: Richard | last post by:
I've seen articles on GotDotNet and elsewhere on how to put a ddl in a datagrid, and have been able to implement this technique. For a new item, among the datagrid columns there is the one ddl for the user to choose an account description, and when the user saves, then the value is saved and displayed in a bound column in the datagrid. So far so good. The problem is when the user edits the line. The ddl is refreshed with all of the...
0
1527
by: Luis Esteban Valencia | last post by:
Hello. I have a datagrid with one row. I have a button that adds a new row. I am trying to implement that when the user selects one product it must change the price on the quantity column. Anyway when the user selects the first dropdownlist the dropdownselected_indexchanged is firring but when the user chagnes the second dropdownlist its not firing. aahh! if the user selects any of both dropdownlist the datagrid stays with only one row?...
1
1202
by: needin4mation | last post by:
I have a dropdownlist that I want to default to the proper value in the list. It should be what the current value of the label is before I press edit. Any ideas?
0
8476
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
8914
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
8820
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...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7433
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...
0
5695
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
4224
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
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.