-
DataGrid with Checkedbox/Radio button
As far as I know, We can added some controls like radio buttons, checked box into DataGrid's Templete Column. But I think it can decrease the performance of Datagrid...
Suppose : Many records are displayed in that grid. Radio buttons are added into the datagrid.. If the user change one radio button to another, it will take long time...
OR.. Checked Boxes are added into the grid and then, the user select all checked boxes by checking "Check All" Checkbox at the top of grid.. It will take very long time if many records are displayed in that grid...
My Problem is I need to use the checked boxes/option boxes in my grid.. But loading time is too much..
So, How should I do?
Any suggestions would be appreciated.
Thanks in advance.
-
Your problem in loading time because ASP.net triggers "evey" event of any server side control by reloaing the page while posting some data back to it, which definitely reduce performance.
So I suggest you to choose javascript for this in collaboration with ASP .net, infact ASP .net translates most of its commands into javascript.
To have radio buttons to select each row inside the datagrid follow the following easy steps:
.ASPX File:
========
In aspx page add the following javascript function
<script language=javascript>
function SelectMeOnly(objRadioButton, grdName) { var i, obj;
//example of radio button id inside the grid (grdAddress): grdAddress__ctl2_radioSelect
for (i=0; i<document.all.length; i++) {
obj = document.all(i);
if (obj.type == "radio") {
if (objRadioButton.id.substr(0, grdName.length) == grdName)
if (objRadioButton.id == obj.id)
obj.checked = true;
else
obj.checked = false;
}
}
}
</script>
Your Radio Button ASP .net Control inside the data grid would look like this:
<asp:RadioButton ID="radioSelect" GroupName='<%#DataBinder.Eval(Container.DataItem,"RecID")%>' Runat=server ></asp:RadioButton>
Here I used GroupName property to just Identify the row no in Database, where datagrid is bound to any datasource in page load event. RecID in this case is the Primary Key in the table holding unique RecID for each row in the table. You can replace this with your table's field name, or remove it at all if you donot want to record the row number for each radio button. You can also use the Text property to set text for the radio button.
Thats all concerned in aspx page.
.CS File
======
Here Make the following function and call it in Page Load event, this function would set the OnClick event of each RadioButton inside the data grid, let say your data grid name is "grdDataGrid":
public void SetGrdRadiosOnClick()
{
int i;
RadioButton B;
for (i = 0; i<grdDataGrid.Items.Count; i++)
{
B = (RadioButton) grdDataGrid.Items[i].FindControl("radioSelect");
B.Attributes.Add("OnClick", "SelectMeOnly(" + B.ClientID + ", "+ "'grdDataGrid'" + ")");
}
}
You got it, Thats all it need to have radio button functionality to select rows in Datagrid and in fastest way.
Final thing, if you want to get which radio is selected and at which row, i.e. which row in database the selected radio button represents then you cn use the following function, let say you have a button name "btnSelect". (Remember we set the Unique Row ID of database in GroupName property of each radio button):
GridName is "grdDataGrid"
RadioButton inside the grid was "radioSelect" which is repeated for each row
public void btnSelect_Click(object sender, System.EventArgs e)
{
RadioButton B;
int i, RecID=0;
for (i = 0; i<grdDataGrid.Items.Count; i++)
{
B = (RadioButton) grdDataGrid.Items[i].FindControl("radioSelect");
if (B.Checked)
RecID = int.Parse(B.GroupName);
}
Response.Redirect("./ProcessRecord.aspx?RecID=" + RecID);
}
Similar Threads
-
By Balaji N.S in forum .NET
Replies: 3
Last Post: 02-17-2007, 02:36 PM
-
By DrunkinP in forum Java
Replies: 0
Last Post: 03-31-2005, 09:36 AM
-
By moben in forum VB Classic
Replies: 6
Last Post: 01-16-2002, 03:05 AM
-
By Wayne in forum VB Classic
Replies: 1
Last Post: 03-09-2001, 09:52 AM
-
By Wendy Lee in forum VB Classic
Replies: 1
Last Post: 03-01-2001, 09:44 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks