By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

DataGrid Validation

P: n/a
Hello Gurus,
Pl. help. I need to validate a control in datagrid based on check box
Basically in a datagrid i have checkbox and textbox control for
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 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"
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<HeaderStyle BackColor="Gainsboro"></HeaderStyle>
<asp:TemplateColumn HeaderText="Major Code">
<asp:Label id=Label1 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.cd_major") %>'>
<asp:DropDownList 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)Con tainer.DataItem)[0])%>"
OnSelectedIndexChanged="cboMajorGrd_SelectedIndexC hanged"

I tried following code in cs file...not sure how to continue..
protected void DataGrid1_ItemCommand(Object sender, DataGridCommandEventArgs
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..
lblMessage.Text ="Textbox not avail";

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.