ASP.NET - Loop

Asked By pradeep kumar
10-Feb-12 06:47 AM
in the grid view when i using the checkbox .... selecting All the rows .... then in the for loop how to check the each row one by one please .....
  dipa ahuja replied to pradeep kumar
10-Feb-12 06:48 AM
Try this way:
 
Add a checkbox in header template:
 
<HeaderTemplate>
  <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox2_CheckedChanged" />
</HeaderTemplate>
 
► and implement the checkedChange:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
  CheckBox chk1 = (CheckBox)GridView1.HeaderRow.FindControl("CheckBox2");
  foreach (GridViewRow r in GridView1.Rows)
  {
    /* search id in itemtemplate */
    CheckBox chkin = (CheckBox)r.FindControl("CheckBox1");
    chkin.Checked = chk1.Checked;
  }    
}
 
 
  pradeep kumar replied to dipa ahuja
10-Feb-12 06:59 AM
nice ... but problem is that when i selecting the three item in the check box with same leave so ... here row will be calculated saferately so in the for loop how to do that ... in the grid view StatusId is their .... here Totaldays - noofdays will be minus .... so one by one it will check then only give the result.... please
thank you
  kalpana aparnathi replied to pradeep kumar
10-Feb-12 02:35 PM
Use this script:

<script language="javascript">

 function SelectAllCheckboxes(spanChk){

   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && 
              elm[i].id!=theBox.id)
     {
       //elm[i].click();
       if(elm[i].checked!=xState)
         elm[i].click();
       //elm[i].checked=xState;
     }
 }
</script>

Create New Account
help
a collection of controls to be created from database. In case of control being a grid, i am fetching all the template fields to be generated in another child collection and will be addind new rows from footer. Initially there will not be any data in grid. This would be a input grid. Issue is that while creating templatefield if i am trying to add calender control it DataControlCellType cellType, DataControlRowState rowState, Int32 rowIndex) \ r \ n at System.Web.UI.WebControls.GridView.InitializeRow(GridViewRow row, DataControlField[] fields) \ r \ n at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 Code \ GR Solution \ GRWorkFlowSystem \ GRWorkFlow \ RequestCreationForm.aspx.cs:line 774 \ r \ n at RequestCreationForm.OnInit(EventArgs e) in d: \ Projects \ SABIC \ Source Code \ GR Solution \ GRWorkFlowSystem \ GRWorkFlow \ RequestCreationForm.aspx.cs:line objScreenProcessConfigurationDTO = null ; cDTOCollection<ScreenProcessConfigurationDTO> objGridChildCollection = null ; TextBox TxtDynamic = null ; DropDownList DdlDynamic = null ; Control CalDynamic = null ; CheckBox ChkDynamic = null ; GridView GrvDynamic = null ; Int32 Counter = 0; DataTable DtDynamic = null ; GridView GrdDynamic = new GridView ControlID; LoadDropDownControl(PopulateDropDownControl(objScreenDropDownValuesDTO), DdlDynamic); break ; case SessionKeys.Calendar: CalDynamic = GenerateCalendar(objScreenProcessConfigurationDTO); break ; case SessionKeys.Checkbox: ChkDynamic = GenerateCheckbox(objScreenProcessConfigurationDTO); break ; case SessionKeys.Grid: { ParentControltype = SessionKeys.Grid; #region "Commented" / / GrdDynamic = GenerateGrid(objScreenProcessConfigurationDTO); / / GrdDynamic.ID = "Grv" + objScreenProcessConfigurationDTO.FieldLabel.Replace(" ", "") + objScreenProcessConfigurationDTO
How to autorefresh a gridview In a ASP.NET page I want to refresh only a gridview in time interval of 30 secs instead out. . . . . . . advance thanks For this you can use the timer of AJAX and put that grid in updated panel. And then on the timer's time elapsed event updated your data grid. You can refresh the data of grid at certain time interval using Ajax update panel. Please check the following article for more details about the logic and code. http: / / asp-net-csharp-vb.blogspot.com / 2009 / 06 / auto-refresh-data-on-page-using-ajax.html Hope time on page load. Write this code: MyLabel.Text = System.DateTime.Now.ToString() BindData() and grid refresh time is: Protected Sub Timer1_Tick( ByVal sender As Object , ByVal e As EventArgs) Label1
Web APPLICATION How to delete a row of data in gridview when after selecting checkbox and click on delete button.How to bind that checkbox control and data to the gridview dynamically? When click on delete button after selecting the checkbox it should delete the row in the table in database.Please give me code for Step 1: Create an .aspx page and add a GridView . Step 2: To create a checkbox in each row, follow these steps: 1. Create a TemplateField inside the < Columns > to add custom content to each column. 2. Inside the TemplateField, create an ItemTemplate with a CheckBox added to it. This will add a checkbox to each row in the grid. < asp : GridView ID = "GridView1" runat = "server" AutoGenerateColumns = "False" DataKeyNames = "EmployeeID" > < Columns > < asp : TemplateField > < ItemTemplate > < asp : CheckBox ID = "cbRows" runat = "server" / > < / ItemTemplate > < / asp : TemplateField > < asp : BoundField DataField = "EmployeeID" HeaderText = "EmployeeID" InsertVisible = "False
Beneath the GridView Please refer the follow the website for code, procedure & image http: / / www.asp.net / data-access / tutorials / batch-deleting-cs For that you have to handle RowDeleting event of Just go thr this code which will explain the same; protected void Page_Load(object sender, EventArgs e) { / / public event GridViewDeleteEventHandler RowDeleting(gv1, e); if (!Page.IsPostBack) { gv.DataSource = createDataSet(); gv.DataBind false; gv1.DataSource = createDataSet(dt1); gv1.DataBind(); gv1.Visible = true; } } } protected void gv1_SelectedIndexChanged(object sender, EventArgs e) { } } Cheers For Your task, you vahe to use GridView1_RowDeleting Event of GridView Control(). I has been configured, bind the gridview with this data source. Step 4: To create a checkbox in each row, follow these steps: 1. Create a TemplateField inside the < Columns > to add custom content to each column. 2. Inside the TemplateField, create an ItemTemplate with a CheckBox added to it. < asp:TemplateField > < ItemTemplate > < asp CheckBox ID = "chkRows" runat = "server" / > < / ItemTemplate > < / asp:TemplateField > This will add a checkbox to each row in the grid. Step 5: Add a button control, and rename it
grid in user control hi all, i need a help for my task i hav a user control which has a grid view control with check boxes in its column when i select some rows and click the submit button . . . the select rows should bind in the another grid view control in my main page how can i do this thanks in advance Muthu C2D69B" HeaderStyle-BackColor = "green" AllowPaging = "true" OnPageIndexChanging = "OnPaging" PageSize = "10" > < Columns > < asp : TemplateField > < HeaderTemplate > < asp : CheckBox ID = "chkAll" runat = "server" onclick = "checkAll(this);" AutoPostBack = "true" OnCheckedChanged = "CheckBox_CheckChanged" / > < / HeaderTemplate > < ItemTemplate > < asp : CheckBox ID = "chk" runat = "server" onclick = "Check_Click(this)" AutoPostBack = "true" OnCheckedChanged = "CheckBox_CheckChanged" / > < / ItemTemplate > < / asp : TemplateField > < asp similar except that the second GridView does not have Pagination and Checkboxes Data Binding the ASP.Net GridView control I have used the Customers table from the Northwind Database for this example. The following function is used to databind the ASP.Net GridView control C# private void BindPrimaryGrid() { string constr = ConfigurationManager .ConnectionStrings["conString"].ConnectionString; string query