473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGrid Validation

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>
<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"
AutoPostBack="true">
</asp:DropDownList>
</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
Nov 17 '05 #1
0 1371

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

Similar topics

0
by: ED M. | last post by:
Hello all...I'm new to the board. I have a problem that I hope someone here might be able to solve for me. I am doing some clientside validation using Javascript. The text I am testing is...
1
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the...
1
by: Stephan Bour | last post by:
Hi, I need to validate a text box in a datagrid nested inside a datalist. All I need is to validate that any text is entered in the textbox. However, a requiredfieldvalidator would not do because...
3
by: Ben | last post by:
Hi, I have a page with a datagrid that you have to scroll to see. I'm using the StrengthControls SmartScroller as recommended to maintain my scroll position. Anyway, inside the datagrid I have...
2
by: rodchar | last post by:
Hey all, I've got an asp.net page that has a textbox on it. The textbox has a requiredfieldvalidation associated with it. I've also got a datagrid with the edit,update,cancel links on it. When...
5
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and...
4
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
1
by: Kris | last post by:
Hi, I have a DataGrid where in each row has couple of text boxes and an update button. Each row is dynamically generated as the number of rows are not known ahead of time. When the user clicks the...
5
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.