I want to Update An Number of goals That a Player Scored so if he socred a goal I want to do an update for his number of goals...
I got an Error in my Code And I don't know how to fix it. Can anyone help me to fix it, please ?
My Code:
string connectionStr = #"Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|\SoccerDataBase.mdb";
using (OleDbConnection sqlCon = new OleDbConnection(connectionStr))
{
sqlCon.Open();
string queryStr = "SELECT Achievement FROM SoccerAchievements WHERE UserID=#AchNums";
OleDbCommand sqlCmd = new OleDbCommand(queryStr, sqlCon);
sqlCmd.Parameters.AddWithValue("#AchNums", (SoccerTable.FooterRow.FindControl("AchNums") as TextBox).Text.Trim());
OleDbDataAdapter dataAdapt = new OleDbDataAdapter(queryStr, sqlCon);
DataSet ds = new DataSet();
dataAdapt.Fill(ds, "SoccerAchievement");
DataRow row = ds.Tables["SoccerAchievement"].Rows[0];
int a = int.Parse(row[3].ToString());
a = a + int.Parse("#AchNums");
string query = "UPDATE SoccerAchievements SET Achievement= '" + a + "' WHERE UserID= #AchNums";
sqlCmd.ExecuteNonQuery();
}
My GridView HTML CODE:
<asp:GridView ID="SoccerTable" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="ID" HeaderText="קוד שחקן" InsertVisible="False"
SortExpression="ID" />
<asp:BoundField DataField="Team" HeaderText="קבוצות" SortExpression="Team" />
<asp:BoundField DataField="Players" HeaderText="שחקנים"
SortExpression="Players" />
<asp:TemplateField HeaderText="הישגים">
<FooterTemplate>
<asp:TextBox ID="AchNums" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button class = "AddButton" ID="AddButton" runat="server" onclick="AddButton_Click" Text="עדכן" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
My Error: There is no row at position 0.
Image:
My Data SoccerAchievements
Image:
Please help me guys :)
Replace this
OleDbDataAdapter dataAdapt = new OleDbDataAdapter(queryStr, sqlCon);
With
OleDbDataAdapter dataAdapt = new OleDbDataAdapter(sqlCmd);
However you may again face error at your int.parse code.please correct that as well.
Related
I'd like to send gridview rows to an email on button press. The number of rows selected vary and use check boxes.
Background:
The app consists of 2 GridViews. One acts as a schedule, the other acts as a holding area for items taken out of the schedule. Included below is what I use to move Items out of the schedule. The code to put items back into schedule is identical, so it was not included.
The email function is to notify the user what specific items were taken out/put into schedule.
GridView1
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID" AllowPaging="True" ShowHeaderWhenEmpty="True" BackColor="White" BorderColor="#003399" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridView1_PageIndexChanging" Width="450px">
<Columns>
<asp:BoundField DataField="VEH_SER_NO" SortExpression="VEH_SER_NO" ReadOnly="True">
<ItemStyle HorizontalAlign="Center" Width="75px" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="DATE_BLD_RATE" SortExpression="DATE_BLD_RATE" ReadOnly="True" DataFormatString="{0:yyyy/MM/dd}">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="SEQ" SortExpression="SEQ" ReadOnly="True">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="SV_TYPE_CD" SortExpression="SV_TYPE_CD" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="COMMENT" SortExpression="COMMENT" Visible="False" ReadOnly="False" />
<asp:TemplateField HeaderText="Select" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSel" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#99CCCC" ForeColor="White" HorizontalAlign="center" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
Code:
protected void cmdMoveRight_Click(object sender, EventArgs e)
{
if (drpReason0.SelectedValue != "" && drpReason.SelectedValue != "")
{
string strSQL = "SELECT VEH_SER_NO, DATE_BLD_RATE, SEQ, SV_TYPE_CD, COMMENT FROM Schedule " +
"WHERE Schedule.id = #ID";
MoveRows(GridView1, strSQL);
}
}
void MoveRows(GridView gv, string strSQL)
{
foreach (GridViewRow OneRow in gv.Rows)
{
CheckBox ckBox = OneRow.FindControl("cHkSel") as CheckBox;
if (ckBox.Checked)
{
int PKID = (int)gv.DataKeys[OneRow.RowIndex]["ID"];
SqlCommand cmdSQL = new SqlCommand(strSQL);
cmdSQL.Parameters.Add("#ID", SqlDbType.Int).Value = PKID;
SqlRun(cmdSQL);
}
}
LoadGrids();
}
public void SqlRun(SqlCommand cmdSQL)
{
using (SqlConnection conn = new SqlConnection(cs))
{
using (cmdSQL)
{
cmdSQL.Connection = conn;
conn.Open();
cmdSQL.ExecuteNonQuery();
}
}
}
i have a small problem with summarizing of the total value of the columns. I have a shopping cart where i want to summarize quantity and price of the item. I've done summarize of prices but when i was trying to multiply it to quantity it didn't work.
.
Could you please give me an advice.
Here is a gridview:
<asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" DataKeyNames="id" ShowFooter="true" ShowHeaderWhenEmpty="true">
<Columns>
<asp:BoundField DataField="item" HeaderText="Item" SortExpression="item"></asp:BoundField>
<asp:BoundField DataField="BEE" HeaderText="Description" SortExpression="BEE"></asp:BoundField>
<asp:BoundField DataField="count" HeaderText="Quantity" SortExpression="count"></asp:BoundField>
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price"></asp:BoundField>
<asp:TemplateField>
<FooterTemplate>
<asp:Label ID="lbltxtTotal" runat="server" Text="Total Price" />
</FooterTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id"></asp:BoundField>
<asp:ButtonField CommandName="Delete" Text="Delete" ButtonType="Button" ShowHeader="True" HeaderText="Delete"></asp:ButtonField>
</Columns>
<EmptyDataTemplate>No Record Available</EmptyDataTemplate>
<FooterStyle BackColor="White" Font-Bold="True"></FooterStyle>
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White"></HeaderStyle>
<PagerStyle HorizontalAlign="Right" BackColor="White" ForeColor="Black"></PagerStyle>
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White"></SelectedRowStyle>
<SortedAscendingCellStyle BackColor="#F7F7F7"></SortedAscendingCellStyle>
<SortedAscendingHeaderStyle BackColor="#4B4B4B"></SortedAscendingHeaderStyle>
<SortedDescendingCellStyle BackColor="#E5E5E5"></SortedDescendingCellStyle>
<SortedDescendingHeaderStyle BackColor="#242121"></SortedDescendingHeaderStyle>
</asp:GridView>
and here is a backend:
protected void Timer1_Tick(object sender, EventArgs e)
{
string Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
string Username_new = Username.Replace("APAC\\", "");
GridView1.DataBind();
//live data
String myquery = "Select * from Basket where Username='" + Username_new + "'";
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
GridView1.FooterRow.Cells[1].Text = "Total Amount";
GridView1.FooterRow.Cells[2].Text = dt.Compute("Sum(price)", "").ToString();
}
This is easy.
Add method to your code:
protected void getSUM()
{
// SQL query that gets total of product sales where category id = 1
string SqlQuery = #"SELECT SUM(ProductSales) AS TotalSales
FROM [NORTHWIND].[dbo].[Sales by Category]
WHERE CategoryID = 1";
// Declare and open a connection to database
SqlConnection conn = new SqlConnection(
ConfigurationManager.ConnectionStrings["NorthwindConnStr"].ConnectionString);
conn.Open();
// Creates SqlCommand object
SqlCommand comm = new SqlCommand(SqlQuery, conn);
// Gets total sales
decimal TotalSales = Convert.ToDecimal(comm.ExecuteScalar());
// Close connection
conn.Close();
conn.Dispose();
comm.Dispose();
// Adds formatted output to GridView footer
GridView1.Columns[1].FooterText = String.Format("{0:c}", TotalSales);
}
In markup code, we'll define footer template and call getSUM method:
<FooterTemplate>
Total sales: <%# getSUM(); %>
</FooterTemplate>
This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 6 years ago.
Edit: This is not a duplicate question as my problem is a tad bit more complicated than a simple NullReferenceException.
This is the bit of code that is giving me problems:
private void BindData()
{
SqlConnection con = new SqlConnection(Connection.constr);
con.Open();
string[] Querys = new string[4];
Querys[0] = "PopulateConstraintTable";
Querys[1] = "PopulateModuleTable";
Querys[2] = "PopulateFeatureTable";
Querys[3] = "PopulateInterfaceTable";
for (int n = 0; n < 4; n++)
{
SqlCommand cmd = new SqlCommand(Querys[n], con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#License", SqlDbType.Int).Value = 20000 + MyGlobals.CurrentOrgID;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable Table = new DataTable();
da.Fill(Table);
((GridView)Page.FindControl("GridView" + (n + 1))).DataSource = Table;
((GridView)Page.FindControl("GridView" + (n + 1))).DataBind();
cmd.ExecuteNonQuery();
}
con.Close();
}
This code SHOULD be populating 4 different Gridviews with the information in those stored procedures, but I get an error at lines
((GridView)Page.FindControl("GridView" + (n + 1))).DataSource = Table;
((GridView)Page.FindControl("GridView" + (n + 1))).DataBind();
that says:
An exception of type 'System.NullReferenceException' occurred in App_Web_30v1z0on.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
Could someone walk me through what is wrong please? Thank you!
EDIT: Markup -
<asp:GridView
ID="GridView1"
runat="server"
CellPadding="6"
GridLines="Horizontal"
Font-Names="Verdana"
Font-Size="10pt"
DataKeyNames="ConstraintID"
AutoGenerateColumns="false"
allowpaging="false"
Width="730px">
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" ForeColor="White" HorizontalAlign="Left" Height="25" Font-Bold="True" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>...</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="false" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:GridView
ID="GridView2"
cellpadding="6"
runat="server"
GridLines="Horizontal"
Font-Names="Verdana"
Font-Size="10pt"
DataKeyNames="ModuleID"
AutoGenerateColumns="False"
onrowcancelingedit="GridView2_RowCancelingEdit"
onrowediting="GridView2_RowEditing"
onrowupdating="GridView2_RowUpdating"
Width="730px">
<HeaderStyle BackColor="#336699" ForeColor="White" HorizontalAlign="Left" Height="25" />
<Columns>...</Columns>
</asp:GridView>
<asp:GridView
ID="GridView3"
runat="server"
CellPadding="6"
GridLines="Horizontal"
Font-Names="Verdana"
Font-Size="10pt"
DataKeyNames="FeatureID"
AutoGenerateColumns="false"
allowpaging="false"
onrowcancelingedit="GridView3_RowCancelingEdit"
onrowediting="GridView3_RowEditing"
onrowupdating="GridView3_RowUpdating"
OnRowDataBound="GridView3_RowDataBound"
Width="730px">
<EditRowStyle Font-Bold="True" />
<HeaderStyle BackColor="#336699" ForeColor="White" HorizontalAlign="Left" Height="25" />
<Columns>...</Columns>
</asp:GridView>
<asp:GridView
ID="GridView4"
runat="server"
CellPadding="6"
GridLines="Horizontal"
Font-Names="Verdana"
Font-Size="10pt"
DataKeyNames="InterfaceID"
AutoGenerateColumns="false"
allowpaging="false"
onrowcancelingedit="GridView4_RowCancelingEdit"
onrowediting="GridView4_RowEditing"
onrowupdating="GridView4_RowUpdating"
OnRowDataBound="GridView4_RowDataBound"
Width="730px">
<EditRowStyle Font-Bold="True" />
<HeaderStyle BackColor="#336699" ForeColor="White" HorizontalAlign="Left" Height="25" />
<Columns>...</Columns>
</asp:GridView>
Answer:
Seeing as how this post was bombarded with people claiming this was a duplicate, and so I can not post an answer, I'm going to put the answer here in an edit (All credit and praise be unto #ConnorsFan)
The solution was replacing the two problem lines of code with
((GridView)Master.FindControl("MainContent").FindControl("GridView" + (n + 1))).DataSource = Table;
((GridView)Master.FindControl("MainContent").FindControl("GridView" + (n + 1))).DataBind();
This is null,
Page.FindControl("GridView" + (n + 1))
Can you paste the markup so that we check it.
This is my aspx page
<asp:GridView ID="GridViews1" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None"
>
<Columns>
<asp:TemplateField HeaderText = "S.No">
<ItemTemplate>
<asp:Label ID="Sno" runat="server" Text= '<%#Eval("id")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Name">
<ItemTemplate >
<a href= "<%# Eval("Photo") %>" > <%# Eval("name") %> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Photo">
<ItemTemplate>
<img src='<%# Eval("Photo") %>' alt='<%# Eval("Name") %>' height= "50px" width = "50px"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
and this is my .cs file
public partial class people_db_mysql : System.Web.UI.Page
{
String MyConString = "SERVER=localhost;" +
"DATABASE=shortandsweet;" +
"UID=root;" +
"PASSWORD=;";
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection(MyConString);
MySqlCommand cmd = new MySqlCommand("SELECT * FROM people_details;", conn);
conn.Open();
DataTable dataTable = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dataTable);
GridViews1.DataSource = dataTable;
GridViews1.DataBind();
}}
now the output i get is
[ S.NO, Name , Photo , sno, name and photo ]
the first three fields are from the aspx page which i want it to be displayed and i dont want the other 3 fields to be displayed any ideas how i might achieve that ?
and moreover ive tried this
GridViews1.Columns[3or4or5].Visible = false; //and it says array out of bounds
however i can hide the 0,1,2 fields with the same command, is there a way to hide the rows generated through the .cs files ?
if i try to limit the rows through the select query it doesnt display anything, i just get a blank screen.
The Gridview control has a property 'AutoGenerateColumns' which has to be set to 'false', otherwise it will autogenerate the columns, even if you have manually added them.
<asp:GridView ID="GridViews1" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AutoGenerateColumns="false"
>
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 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...