Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid EditItemTemplate-- how to retrieve a DropDownList validator?

Reply
Thread Tools

DataGrid EditItemTemplate-- how to retrieve a DropDownList validator?

 
 
Steve Hershoff
Guest
Posts: n/a
 
      04-11-2007
Hi everyone,

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

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

<TemplateColumn>
<EditItemTemplate>
<aspropDownList OnSelectedIndexChanged="some method">
</aspropDownList>
</EditItemTemplate>
</TemplateColumn>


<TemplateColumn>
<EditItemTemplate>
<asp:TextBox id="textbox1">
</asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="textbox1">
</asp:RequiredFieldValidator>
</EditItemTemplate>
</TemplateColumn>



When I'm in the method that catches the SelectedIndexChanged event, can I
somehow retrieve the RequiredFieldValidator 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!


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      04-11-2007
Hi Steve,

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

-- beging aspx code --

<script runat="server">

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

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

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = dg.EditItemIndex;
if (index >= 0)
{
DataGridItem item = dg.Items[index];

RequiredFieldValidator validator = (RequiredFieldValidator)
item.FindControl("rfv");
TextBox textBox = (TextBox) item.FindControl("textBox1");
}
}
protected void dg_EditCommand(object source, DataGridCommandEventArgs e)
{
((DataGrid) source).EditItemIndex = e.Item.ItemIndex;
BindData();
}


</script>

<aspataGrid runat="server" ID="dg" AutoGenerateColumns="false"
OnEditCommand="dg_EditCommand">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
column1
</ItemTemplate>
<EditItemTemplate>
<aspropDownList runat="server" ID="ddl"
OnSelectedIndexChanged="DropDownList1_SelectedInde xChanged"
AutoPostBack="true">
<asp:ListItem Text="1" />
<asp:ListItem Text="2" />
<asp:ListItem Text="3" />
</aspropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
column2
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="textbox1" runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="textbox1" runat="server"
ID="rfv">
</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn CommandName="Edit" Text="Edit" />
</Columns>
</aspataGrid>

-- 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
> EditItemTemplate that contains an ASP.Net DropDownList. I'm catching this
> DropDownList's SelectedIndexChanged event.
>
> I also have another TemplateColumn, with a RequiredFieldValidator that
> validates a TextBox in the column. It all looks like this, in broad
> strokes:
>
> <TemplateColumn>
> <EditItemTemplate>
> <aspropDownList OnSelectedIndexChanged="some method">
> </aspropDownList>
> </EditItemTemplate>
> </TemplateColumn>
>
>
> <TemplateColumn>
> <EditItemTemplate>
> <asp:TextBox id="textbox1">
> </asp:TextBox>
> <asp:RequiredFieldValidator ControlToValidate="textbox1">
> </asp:RequiredFieldValidator>
> </EditItemTemplate>
> </TemplateColumn>
>
>
>
> When I'm in the method that catches the SelectedIndexChanged event, can I
> somehow retrieve the RequiredFieldValidator 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!
>
>
>

 
Reply With Quote
 
 
 
 
Steve Hershoff
Guest
Posts: n/a
 
      04-11-2007
Thanks very much Milosz. This looks like just what I need.

-Steve


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
cannot retrieve dropdownlist selected value nLL ASP .Net 3 01-28-2009 05:49 AM
DataGrid EditItemTemplate-- how to retrieve a DropDownList validator? Steve Hershoff ASP .Net Datagrid Control 2 04-11-2007 08:12 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM
Retrieve value from hidden/disabled DropDownList? Cipher ASP .Net 1 07-11-2004 03:52 AM



Advertisments