2016-08-24 2 views
-1

Ich habe dies versucht, aber nicht ausgewählt Wert auf einen anderen Rasteransicht bekommenDatagridview mit Checkbox

string data = ""; 
    foreach (GridViewRow row in GridView5.Rows) 
    { 
     if (row.RowType == DataControlRowType.DataRow) 
     { 
      CheckBox chkRow = (row.Cells[0].FindControl("chkCtr") CheckBox); 
      if (chkRow.Checked) 
      { 
       string Brand_Name = row.Cells[1].Text; 
       string Market_Name = row.Cells[2].Text; 
       string USC = row.Cells[3].Text; 
       string Manufacture = row.Cells[4].Text; 
       data = data + Brand_Name + " , "; 
       //;+ Market_Name + " , " + USC + ","+Manufacture+""; 

       gvrProducts.Visible = true; 


       gvrProducts.DataSource = data; 
       // ListBox1.DataBind(); 
       gvrProducts.DataBind(); 
      } 
     } 
    } 

Bitte helfen

Antwort

0

Versuchen Sie, diese

Private Sub Gridview_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles Gridview.CurrentCellDirtyStateChanged 
    Gridview.CommitEdit(DataGridViewDataErrorContexts.Commit) 
End Sub 

Dann

Private Sub Gridview_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles Gridview.CellValueChanged 
    Try 
     Gridview.CommitEdit(DataGridViewDataErrorContexts.Commit) 
     'add commit when chckbox is checked. Then your procedure/staff here. 
     'Or call your for loop here 
    Catch ex As Exception 
    End Try 
End Sub 
hinzufügen
1

GridView erfordert data source control wie ein LinqDataSource-, ObjectDataSource- oder SqlDataSource-Steuerelement. Sie binden Ihre Gridview mit einer String-Variable (weiß nicht, wie es Daten binden). Es gibt viele Möglichkeiten, die Gridview zu binden, aber ich erkläre die eine Art und Weise durch Erstellen dynamischer DataTable:

Erstellen Sie eine leere DataTable für zweiter gridview:

DataTable dt = new DataTable(); 
DataRow dr = null; 
dt.Columns.Add(new DataColumn("Brand_Name", typeof(string))); 
dt.Columns.Add(new DataColumn("Market_Name", typeof(string))); 
dt.Columns.Add(new DataColumn("USC", typeof(string))); 
dt.Columns.Add(new DataColumn("Manufacture", typeof(string))); 

Danach Zeilen in Ihrer foreach-Schleife zu dieser Datentabelle hinzufügen:

foreach (GridViewRow row in GridView5.Rows) 
     { 
      if (row.RowType == DataControlRowType.DataRow) 
      { 
       CheckBox chkRow = (row.Cells[0].FindControl("chkCtr") CheckBox); 
       if (chkRow.Checked) 
       { 
       dr = dt.NewRow(); 
       dr["Brand_Name"] = row.Cells[1].Text; 
       dr["Market_Name"] = row.Cells[2].Text; 
       dr["USC"] = row.Cells[3].Text; 
       dr["Manufacture"] = row.Cells[4].Text; 
       dt.Rows.Add(dr);     

       } 
      } 
     } 

binden Sie dann Ihre gridview mit Datentabelle

if(dt.Rows.Count>0) 
{ 
gvrProducts.Visible = true; 
gvrProducts.DataSource = dt; 
gvrProducts.DataBind(); 
} 
+0

Wow, das ist ultimative Lösungen !! .. Danke. Ich werde mit mehr Zweifeln kommen;) – Prashanth

Verwandte Themen