C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Gridview Checkboxes


Posted Date: 04 Sep 2008      Total Responses: 2

Posted By: Yasotha       Member Level: Silver     Points: 1



hi

I am having check boxes in gridview. Binding coding as follows

<ItemTemplate>
<input id="<%#DataBinder.Eval(Container.DataItem, "UserID")%>" name="CheckboxMail" type="checkbox" />
</ItemTemplate>

This checkboxes are displaying well. But i want to get the selected checkbox id's in javascript. for that am using follwing code as follows

var c=document.getElementById("CheckboxMail");
alert(c.length);

c.length is not working. It is giving alert message as undefined.
how can i get the length of the CheckboxMail object?





Responses

Author: Gaurav Agrawal    04 Sep 2008Member Level: DiamondRating:     Points: 3

do this in *.aspx page in ur grid

<asp:GridView ID="grid_company" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="200%" AllowPaging="true" PageSize="20"
OnPageIndexChanging="grid_company_PageIndexChanging">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkcust" runat="server" value='<%# Bind("companyid") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Company Details" DataField="companydetail">
<ItemStyle HorizontalAlign="Left" Font-Bold="false" />
</asp:BoundField>
<asp:BoundField HeaderText="Address" DataField="address">
<ItemStyle HorizontalAlign="Left" Font-Bold="false" />
</asp:BoundField>
<asp:BoundField HeaderText="Contact No." DataField="contact">
<ItemStyle HorizontalAlign="Left" Font-Bold="false" />
</asp:BoundField>
<asp:BoundField HeaderText="Email-ID" DataField="Email">
<ItemStyle HorizontalAlign="Left" Font-Bold="false" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="false" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<PagerSettings Mode="NumericFirstLast" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="false" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Left" Font-Bold="True"
Font-Underline="True" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>


By using javascript u can get the value by using this
for(var i=2;i<200;i++)
{
if(document.getElementById('ctl00_cpPage_grid_company_ctl0'+i+'_chkcust').checked==true)
alert(document.getElementById('ctl00_cpPage_grid_company_ctl0'+i+'_chkcust').value);
}

GA



Author: ANIL PANDEY    08 Sep 2008Member Level: DiamondRating:     Points: 3

hi,

u can refer the Following code...

function IsChecked() // To Check The CheckBox selection
{
var ReturnValue=0;
var RowCount=0;
RowCount=<%= grdArticle.Rows.Count %>; //Getting number of rows in gridview
ReturnValue=IsSelected('ctl00_ContentPlaceHolder1_grdArticle_ctl',RowCount);

if (ReturnValue==0)
{
alert('Please select article(s) to delete.!');
return false;
}
else
{
return confirm('Delete Articles(s)?');
}
}


Regards
Anil Pandey

Thanks & Regards
Anil Kumar Pandey



Post Reply
You must Sign In to post a response.
Next : Window Minimize
Previous : Free Javascript tutorials for commercial purpose
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use