C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » JavaScript »

Gridview Checkboxes


Posted Date: 04 Sep 2008      Posted By: Yasotha      Member Level: Silver     Points: 1   Responses: 2



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: 3 out of 53 out of 53 out of 5     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

Thanks & Regards,

Gaurav Agrawal
Sr.Software Engineer
gaur1982@yahoo.com
09829373514



Author: Anil Kumar Pandey    08 Sep 2008Member Level: DiamondRating: 3 out of 53 out of 53 out of 5     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

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Window Minimize
Previous : Free Javascript tutorials for commercial purpose
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use