PC Review


Reply
Thread Tools Rate Thread

DataGrid Validation

 
 
Krish
Guest
Posts: n/a
 
      27th Sep 2005
Hello Gurus,
Pl. help. I need to validate a control in datagrid based on check box
selection.
Basically in a datagrid i have checkbox and textbox control for
edititemtemplate.
If checkbox is selected i valid entry in textbox , if checkbox is not
selected , no entry should be made in textbox.
How do i write this...in csharp..

I tried this ...but not sure how to continue
HTML code looks like this
<asp:datagrid id="DataGrid1" runat="server" Width="969px"
BackColor="#AAD2FF" AllowPaging="True"
AllowSorting="True" OnItemCommand="DataGrid1_ItemCommand"
BorderColor="CornflowerBlue" OnDeleteCommand="DataGrid1_Delete"
OnEditCommand="DataGrid1_Edit" OnCancelCommand="DataGrid1_Cancel"
OnPageIndexChanged="Major_Page" AutoGenerateColumns="False"
OnSortCommand="Major_Sort" Font-Size="7pt" Font-Name="arial"
OnUpdateCommand="DataGrid1_Update"
Font-Names="arial">
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<HeaderStyle BackColor="Gainsboro"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Major Code">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.cd_major") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList id=cboMajorGrd style="WIDTH: 259px; HEIGHT:
23px" runat="server" Width="131px" DataSource="<%#TempDataView%>"
DataTextField="ds_desc" DataValueField="cd_value" SelectedIndex="<%#
GetMajorDesc((string)((System.Data.DataRowView)Container.DataItem)[0])%>"
OnSelectedIndexChanged="cboMajorGrd_SelectedIndexChanged"
AutoPostBack="true">
</aspropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
......

I tried following code in cs file...not sure how to continue..
protected void DataGrid1_ItemCommand(Object sender, DataGridCommandEventArgs
e)
{
CheckBox chkTrans = ((CheckBox)e.Item.FindControl("chkTranslateEdit"));
if (chkTrans != null)
{
bool bChkTrans = chkTrans.Checked;
if (bChkTrans == true)
{
TextBox txtExpire = ((TextBox)e.Item.FindControl("txtDtExpire"));
if (txtExpire !=null)
{
if (txtExpire.Text.Trim() == "")
{
lblMessage.Text ="Textbox Empty";
e.Item.Attributes.Add("onclick","alert('pl enter dt expire');"); --
This doesnt seem to be right!!! because it doesnt fire at all...After
validation i need cursor to go to that textbox... PL HELP..
}
}
else
{
lblMessage.Text ="Textbox not avail";
}
}
}
}

Krish


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Custom Column Validation or DataGrid Cell Validation Stanislav Nedelchev Microsoft ADO .NET 0 15th Dec 2005 10:28 AM
datagrid validation =?Utf-8?B?cm9kY2hhcg==?= Microsoft ASP .NET 2 11th Oct 2004 02:39 AM
Validation for DataGrid Matthias Marx Microsoft ASP .NET 2 7th Sep 2004 12:00 PM
validation of a datagrid claire Microsoft C# .NET 1 11th Jun 2004 12:36 PM
DataGrid Validation Ann Marinas Microsoft C# .NET 1 23rd Jan 2004 06:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:42 AM.