Click here to Skip to main content
15,886,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing the client side validation on grid view . please give me the answer as soon as possible
Posted
Updated 26-Jul-12 3:32am
v2
Comments
Vani Kulkarni 26-Jul-12 9:33am    
Removed urgency.
Vani Kulkarni 26-Jul-12 9:35am    
What have you tried till now? Post the specific code where you are facing issue.

Did you try anything? Please do make an effort, you may find it's not that difficult.

These articles will help you to learn:
JQuery to Enable and Disable Textbox when CheckBox is Checked with Gridview [^]
Check/uncheck CheckBox in a GridView using Javascript[^]
Enable textbox in gridview on click checkbox [^]
 
Share this answer
 
Comments
BillW33 26-Jul-12 10:01am    
Good advice, worth a +5.
Sandeep Mewara 26-Jul-12 13:25pm    
Thanks.
Giving you a ready sample. Say below is your grid view

XML
<asp:GridView ID="gvM" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox runat="server" ID="chkIs" onclick="GetCheckStatus()"></asp:CheckBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:TextBox runat="server" ID="txtId"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField AccessibleHeaderText = "Name" DataField="Name" />
        </Columns>
    </asp:GridView>

Have a script which will be called every time when the ckeck box is checked or unchecked.
XML
<script language="javascript" type="text/javascript">
function GetCheckStatus() {
 var srcControlId = event.srcElement.id;
 var targetControlId = event.srcElement.id.replace('chkIs', 'txtId');
 if (document.getElementById(srcControlId).checked)
      document.getElementById(targetControlId).disabled = false;
 else
      document.getElementById(targetControlId).disabled = true;
}
        </script>

In your aspx.cs page bind the grid with appropriate data source as below.
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
DataRow dr = dt.NewRow();
dr["Name"] = "Das";
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1["Name"] = "Shon";
dt.Rows.Add(dr1);
gvM.DataSource = dt;
gvM.DataBind();
}
 
Share this answer
 
Comments
momo14 1-Nov-12 11:03am    
Very Very Nice solution,
I like this.
Thank you very much
Check this article. I have explained how to make fields editable and noneditable inside gridview using checkbox.

http://www.c-sharpcorner.com/UploadFile/1a81c5/non-editable-fields-in-Asp-Net-gridview/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900