Adding All Rows Checkbox for Unknown Gridview Data Source
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>开发者_Python百科;
</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 this article, but in this article Gridview a normal data source. I adding programaticly.
You are going to have to switch AutoGenerated
columns off and used defined ones instead:
<asp:GridView ID="GridView1" runat="server" Width="16px" BackColor="White"
BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Horizontal" Height="16px" AutoGenerateColumns="false">
<!-- put your style stuff here -->
<asp:BoundField HeaderText="Text" DataField="HESAP_NO" />
<asp:BoundField HeaderText="Text" DataField="TEKLIF" />
<asp:BoundField HeaderText="Text" DataField="MUSTERI" />
<asp:BoundField HeaderText="Text" DataField="MARKA" />
<asp:BoundField HeaderText="Text" DataField="SASI_NO" />
<asp:BoundField HeaderText="Text" DataField="SASI_DURAM" />
<asp:BoundField HeaderText="Text" DataField="TAS_MAR" />
<asp:BoundField HeaderText="Text" DataField="RISK" />
<asp:BoundField HeaderText="Text" DataField="Text" />
<asp:CheckBoxField DataField="NameCheckBoxField1" HeaderText="NameCheckBoxField1" />
<asp:BoundField HeaderText="Text" DataField="MV" />
<asp:CheckBoxField DataField="NameCheckBoxField2" HeaderText="NameCheckBoxField2" />
</asp:GridView>
You will also need to change your SQL to return two fields that the CheckBoxField
can map to. Those fields should contain a bit field with true set for all cases. This will allow the data to be automatically bound to the CheckBoxField
and checked by default.
EG:
SELECT
-- all our fields
'NameCheckBoxField1' = 0x1,
'NameCheckBoxField2' = 0x1
FROM
-- etc...
精彩评论