2
Reply

Adding All Rows Checkbox for Unknown Gridview Data Source

Soner Gonul

Soner Gonul

Mar 23 2011 6:52 PM
2.7k
Hello 

I have a Gridview like this.

<asp:GridView ID="GridView1" runat="server"  
         
Width="16px" BackColor="White" BorderColor="#E7E7FF"
       
BorderStyle="None" BorderWidth="1px" CellPadding="3"
       
GridLines="Horizontal" Height="16px" >
       
<AlternatingRowStyle BackColor="#F7F7F7" />
       
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
       
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
       
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
       
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
       
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
       
<sortedascendingcellstyle backcolor="#F4F4FD" />
       
<sortedascendingheaderstyle backcolor="#5A4C9D" />
       
<sorteddescendingcellstyle backcolor="#D8D8F0" />
       
<sorteddescendingheaderstyle backcolor="#3E3277" />

<SortedAscendingCellStyle BackColor="#F4F4FD"></SortedAscendingCellStyle>

<SortedAscendingHeaderStyle BackColor="#5A4C9D"></SortedAscendingHeaderStyle>

<SortedDescendingCellStyle BackColor="#D8D8F0"></SortedDescendingCellStyle>

<SortedDescendingHeaderStyle BackColor="#3E3277"></SortedDescendingHeaderStyle>
   
</asp:GridView>

Programaticly, i adding a data source this Gridview.

protected void SendToGridview_Click(object sender, EventArgs e)
   
{
       
Calculate.Visible = true;
        MV_Label
.Visible = true;
        RISK_Label
.Visible = true;

       
string strQuery;
       
string ConnectionString = ConfigurationManager.ConnectionStrings["ora"].ConnectionString;

       
OracleConnection myConnection = new OracleConnection(ConnectionString);

        strQuery
= @"SELECT A.HESAP_NO, A.TEKLIF_NO1 || '/' || A.TEKLIF_NO2 AS TEKLIF, A.MUS_K_ISIM AS MUSTERI,
                    B.MARKA, C.SASI_NO, C.SASI_DURUM, D.TAS_MAR, NVL(RISK_SASI(A.TEKLIF_NO1, A.TEKLIF_NO2, C.URUN_SIRA_NO, C.SIRA_NO),0) AS RISK,
                    NVL(MV_SASI(A.TEKLIF_NO1, A.TEKLIF_NO2, C.SIRA_NO, C.URUN_SIRA_NO, SYSDATE),0) AS MV
                    FROM S_TEKLIF A,  S_URUN B, S_URUN_DETAY C, KOC_KTMAR_PR D
                    WHERE A.TEKLIF_NO1 || A.TEKLIF_NO2 = B.TEKLIF_NO1 || B.TEKLIF_NO2
                    AND A.TEKLIF_NO1 || A.TEKLIF_NO2 = C.TEKLIF_NO1 || C.TEKLIF_NO2
                    AND B.SIRA_NO = C.URUN_SIRA_NO
                    AND B.DISTRIBUTOR = D.DIST_KOD
                    AND B.MARKA = D.MARKA_KOD
                    AND B.URUN_KOD = D.TAS_KOD "
;

       
string param = "";
       
foreach (ListItem l in CheckBoxList1.Items)
       
{
           
if (l.Selected)
           
{
                param
+= string.Format("'{0}'", l.Value);
                param
+= ",";
           
}
       
}
        param
= param.Remove(param.Length - 1);

        strQuery
= strQuery + " AND A.HESAP_NO IN (" + param + ")";

       
OracleCommand myCommand = new OracleCommand(strQuery, myConnection);
        myCommand
.CommandType = System.Data.CommandType.Text;
        myCommand
.Connection = myConnection;

        myCommand
.CommandText = strQuery;

        myConnection
.Open();

       
OracleDataReader dr = myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

       
GridView1.DataSource = dr;
       
GridView1.DataBind();
       
GridView1.Visible = true;

        myConnection
.Close();
   
}


This is my Gridview looks;



What i want is, i want to add checkboxes column after RISK column and MV column.

I mean, columns looks like, HESAP_NO, TEKLIF, MUSTERI, MARKA, SASI_NO, SASI_DURUM, TAS_MAR, RISK, (CheckBoxes), MV, (Checkboxes). Totaly should be 11 column.

And i want all checkboxes is checked as a default.

How can i do that?

I read http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-checkboxes-cs article, but in this article Gridview a normal data source. I adding programaticly.


Answers (2)