Add generated attendance details to Database asp.net c# - c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class UserAttendance : System.Web.UI.Page
{
SqlConnection vid = new SqlConnection("Data Source=DESKTOP-430E2O0\\SQLEXPRESS;Initial Catalog=mca;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Calendar1.Visible = true;
TextBox1.Visible = true;
String str = "select * from Student where (Course like '%' + #search + '%')";
String str1 = "select * from Student where (Semester like '%' + #search + '%')";
SqlCommand xp = new SqlCommand(str, vid);
SqlCommand xp1 = new SqlCommand(str1, vid);
xp.Parameters.Add("#search", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem.Text;
xp1.Parameters.Add("#search", SqlDbType.NVarChar).Value = DropDownList2.SelectedItem.Text;
vid.Open();
xp.ExecuteNonQuery();
xp1.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = xp;
da.SelectCommand = xp1;
DataSet ds = new DataSet();
da.Fill(ds, "Course");
da.Fill(ds, "Semester");
GridView1.DataSource = ds;
GridView1.DataBind();
vid.Close();
Button2.Visible = true;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
Calendar1.Visible = false;
}
protected void Button2_Click(object sender, EventArgs e)
{
//I wish to use this button to save details to the database
}
}
<%# Page Title="" Language="C#" MasterPageFile="~/User.master" AutoEventWireup="true" CodeFile="UserAttendance.aspx.cs" Inherits="UserAttendance" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 179px;
}
.auto-style3 {
width: 6px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" runat="server">
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Course] FROM [Course]"></asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Course" DataValueField="Course">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="Semester" DataValueField="Semester">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource3" DataTextField="Subject" DataValueField="Subject">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" Width="49px" />
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="False"></asp:Calendar>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Visible="False"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Semester] FROM [Semester]"></asp:SqlDataSource>
</td>
<td>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server">
<asp:ListItem>Present</asp:ListItem>
<asp:ListItem>Absent</asp:ListItem>
<asp:ListItem>Holiday</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:studentConnectionString %>" SelectCommand="SELECT [Subject] FROM [Subject]"></asp:SqlDataSource>
</td>
<td style="text-align: justify">
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Save" Visible="False" Width="58px" />
</td>
<td class="auto-style3"> </td>
</tr>
</table>
</form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
</asp:Content>
I have a textbox which contains date(out side the Gridview)
I have a dropdownlist in the gridview as a templatefield(Absent/Present)
I have a button called "save" outside of the grid view
When I press the save button the details should go to database and should be saved in a table Attendance.
Columns of Attendance Table
1.ID
2.Name
3.Course
4.Semester
5.Date
6.Status(Absent/Present)

Related

Running Total Gridview

any idea how to get a running total (cumulative total ?) for each row in a gridview? Also the gridview shows the records for an apt/villa choosed by dropdown list. Records are ordered by Trans_ID.
This is the code:
<table cellspacing="1" class="auto-style1">
<tr>
<td class="auto-style22">
<strong>
<asp:Label ID="Label1" runat="server" Text="Apt/Villa"
CssClass="auto-style10" BackColor="White" Font-Bold="True" Font-Names="Arial
Narrow"></asp:Label>
</strong>
</td>
<td class="auto-style21">
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="RecordPaymentAptDropDown" DataTextField="Apt"
DataValueField="Apt_ID" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" CssClass="auto-
style19" BackColor="#CC99FF">
</asp:DropDownList>
<asp:SqlDataSource ID="RecordPaymentAptDropDown" runat="server"
ConnectionString="<%$ ConnectionStrings:db71ConnectionString2 %>"
SelectCommand="SELECT [Apt], [Apt_ID] FROM [Apartments]">
</asp:SqlDataSource>
</td>
<td class="auto-style20"> </td>
</tr>
<tr>
<td class="auto-style22">
<strong>
<asp:Label ID="Label2" runat="server" Text="Date"
CssClass="auto-style10" BackColor="White" Font-Bold="True" Font-Names="Arial
Narrow"></asp:Label>
</strong>
</td>
<td class="auto-style21">
<asp:TextBox ID="TextBox4" runat="server" TextMode="Date"
ToolTip="Enter date in fromat: dd/mm/yyyy" CssClass="auto-style6"
BackColor="#CC99FF"></asp:TextBox>
</td>
<td class="auto-style20"> </td>
</tr>
<tr>
<td class="auto-style22">
<strong>
<asp:Label ID="Label3" runat="server" Text="Description"
CssClass="auto-style10" BackColor="White" Font-Bold="True" Font-Names="Arial
Narrow"></asp:Label>
</strong>
</td>
<td class="auto-style21">
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="RecordPaymentDescriptionDropDown" DataTextField="Description"
DataValueField="Desc_ID" CssClass="auto-style19" BackColor="#CC99FF">
</asp:DropDownList>
<asp:SqlDataSource ID="RecordPaymentDescriptionDropDown"
runat="server" ConnectionString="<%$ ConnectionStrings:db71ConnectionString2
%>" SelectCommand="SELECT [Description], [Desc_ID] FROM [Descr]">
</asp:SqlDataSource>
</td>
<td class="auto-style20"> </td>
</tr>
<tr>
<td class="auto-style24">
Income/Expenses</td>
<td class="auto-style21">
<asp:DropDownList ID="DropDownList3" runat="server"
CssClass="auto-style19" BackColor="#CC99FF">
<asp:ListItem>Please choose</asp:ListItem>
<asp:ListItem Value="1">Income</asp:ListItem>
<asp:ListItem Value="2">Expenses</asp:ListItem>
</asp:DropDownList>
</td>
<td class="auto-style20"> </td>
</tr>
<tr>
<td class="auto-style23">
<asp:Label ID="Label8" runat="server" BackColor="White"
CssClass="auto-style10" Font-Bold="True" Font-Names="Arial Narrow"
Text="Amount"></asp:Label>
</td>
<td class="auto-style11">
<asp:TextBox ID="TextBox1" runat="server" Width="150px"
CssClass="auto-style6" BackColor="#CC99FF"></asp:TextBox>
</td>
<td class="auto-style12"></td>
</tr>
<tr>
<td class="auto-style22">
<strong>
<asp:Label ID="Label6" runat="server" Text="Comment"
CssClass="auto-style10" BackColor="White" Font-Names="Arial Narrow">
</asp:Label>
</strong>
</td>
<td class="auto-style21">
<asp:TextBox ID="TextBox3" runat="server" Height="58px"
TextMode="MultiLine" Width="344px" CssClass="auto-style6"
BackColor="#CC99FF"></asp:TextBox>
</td>
<td class="auto-style20"> </td>
</tr>
<tr>
<td class="auto-style22">
</td>
<td class="auto-style21">
</td>
<td class="auto-style20">
</td>
</tr>
<tr>
<td class="auto-style22"> </td>
<td class="auto-style21">
</td>
<td class="auto-style20"> </td>
</tr>
<tr>
<td class="auto-style22">
<asp:Button ID="Button1" runat="server" Text="Save"
OnClick="Button1_Click" CssClass="auto-style6" BackColor="#000099" Font-
Bold="True" Font-Size="Large" ForeColor="Lime" Height="33px" Width="98px" />
</td>
<td class="auto-style21">
</td>
<td class="auto-style20"> </td>
</tr>
<tr>
<td colspan="3" class="auto-style9">
<asp:SqlDataSource ID="SqlDataSourceRecordPayment1"
runat="server" ConnectionString="<%$ ConnectionStrings:db71ConnectionString2
%>" DeleteCommand="DELETE FROM Trans WHERE Trans_ID = #Trans_ID"
SelectCommand="SELECT Apt, Date, Income, Expenses, Description, Trans_ID,
Memo, OwnerName FROM TransApt WHERE (Apt_ID = #Apt_ID)">
<DeleteParameters>
<asp:Parameter Name="Trans_ID" />
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="Apt_ID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="Trans_ID"
DataSourceID="SqlDataSourceRecordPayment1" GridLines="Horizontal"
CssClass="auto-style6" Width="100%" OnRowDataBound="GridView1_RowDataBound"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" ShowFooter="True">
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:BoundField DataField="Trans_ID"
HeaderText="Trans_ID" SortExpression="Trans_ID" ReadOnly="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="Apt" HeaderText="Apt"
SortExpression="Apt" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="OwnerName"
HeaderText="OwnerName" SortExpression="OwnerName" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Date" HeaderText="Date"
SortExpression="Date" DataFormatString="{0:dd/MM/yyyy}" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Income" HeaderText="Income"
SortExpression="Income" DataFormatString="{0:n}" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Expenses"
HeaderText="Expenses" SortExpression="Expenses" DataFormatString="{0:n}" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Memo" HeaderText="Comment"
SortExpression="Memo" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
</Columns>
<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" />
</asp:GridView>
<br class="auto-style6" />
</td>
</tr>
</table>
This is code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace HHCondominium
{
public partial class RecordPayment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Username"] == null)
Response.Redirect("Login.aspx", true);
}
protected void DropDownList2_SelectedIndexChanged(object sender,
EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection vid = new SqlConnection("Data Source = s1.XXXX.com;
Initial Catalog = db71; Persist Security Info = True; User ID = XXXX;
Password = XXXXX");
if (DropDownList3.SelectedValue == "1")
{
SqlCommand xp = new SqlCommand("Insert into Trans(Apt_ID, Date,
Description_ID, Income, Memo) Values (#Apt_ID, #Date, #Description_ID,
#Income, #Memo)", vid);
xp.Parameters.AddWithValue("#Apt_ID", DropDownList1.Text);
xp.Parameters.AddWithValue("#Date", TextBox4.Text);
xp.Parameters.AddWithValue("#Description_ID",
DropDownList2.Text);
xp.Parameters.AddWithValue("#Income", TextBox1.Text);
xp.Parameters.AddWithValue("#Memo", TextBox3.Text);
vid.Open();
xp.ExecuteNonQuery();
vid.Close();
}
else if (DropDownList3.SelectedValue == "2")
{
SqlCommand xp = new SqlCommand("Insert into Trans(Apt_ID, Date,
Description_ID, Expenses, Memo) Values (#Apt_ID, #Date, #Description_ID,
#Expenses, #Memo)", vid);
xp.Parameters.AddWithValue("#Apt_ID", DropDownList1.Text);
xp.Parameters.AddWithValue("#Date", TextBox4.Text);
xp.Parameters.AddWithValue("#Description_ID",
DropDownList2.Text);
xp.Parameters.AddWithValue("#Expenses", TextBox1.Text);
xp.Parameters.AddWithValue("#Memo", TextBox3.Text);
vid.Open();
xp.ExecuteNonQuery();
vid.Close();
}
{
string msgstring = "Your data has been saved";
string content = "window.onload=function(){ alert('";
content += msgstring;
content += "');";
content += "window.location='";
content += Request.Url.AbsoluteUri;
content += "';}";
ClientScript.RegisterStartupScript(this.GetType(),
"SuccessMessage", content, true);
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{ }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{
}
Double totalIncome = 0;
Double totalExpenses = 0;
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
totalIncome += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem,
"Income"));
totalExpenses +=
Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Expenses"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[5].Text = "Grand Total";
e.Row.Cells[5].Font.Bold = true;
e.Row.Cells[6].Text = totalIncome.ToString();
e.Row.Cells[6].Font.Bold = true;
e.Row.Cells[7].Text = totalExpenses.ToString();
e.Row.Cells[7].Font.Bold = true;
e.Row.Cells[8].Text = (totalIncome-totalExpenses).ToString();
e.Row.Cells[8].Font.Bold = true;
}
}
}
}
What I'm trying to achieve is this:
enter image description here
I've tried many things that I've found on a internet but no luck.
Thanks guys,
You can do this in the RowDataBound event. First, add the event to the GridView and add a Label to display the total value.
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Balance">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Then in code behind
int total = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the row is a datarow
if (e.Row.RowType == DataControlRowType.DataRow)
{
//cast the dataitem back to a row
DataRowView row = e.Row.DataItem as DataRowView;
//add the row value to the total
total += Convert.ToInt32(row["Balance"]);
//use findcontrol to locate the label in the row
Label lbl = e.Row.FindControl("Label1") as Label;
//display the totals in the row
lbl.Text = string.Format("{0:N0}", total);
}
}

Update MySQL using HyperLink ASP.NET

I store all data in MySQL and display it's some colums in gridview. Gridview's delete button works fine. I would like to edit datas so created HyperLink. it navigates another url and gets values from MySQL DB and sets textboxes, textareas. Everything is fine until this time but I try to edit values in new page it sets old values in DB. How i can solve this problem?
This my Main Page which has gridview and delete button, hyperlink KayitGoruntule.aspx;
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="KayitGoruntule.aspx.cs" Inherits="gop.KayitGoruntule" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.string {
text-align: left;
}
</style>
</head>
<body>
<center><asp:Image ID="Banner" runat="server" ImageUrl="images/logo.png" Height="88px" Width="509px"></asp:Image></center>
<form id="form1" runat="server">
<br />
<div>
<asp:GridView ID="gvMysqlData" runat="server" CssClass="string"
SelectedIndex="0" DataKeyNames="id"
ShowHeaderWhenEmpty="True" OnRowDeleting="gvMysqlData_RowDeleting" Height="95px" Width="492px" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Width="15%">
<ItemTemplate>
<asp:HyperLink ID="hpr1" runat="server" NavigateUrl='<%# string.Format("KayitAyrinti.aspx?id={0}",Eval("id")) %>'>
<img src="images/edit.png" />
</asp:HyperLink>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</div>
</form>
</body>
</html>
Navigated Url's page KayitAyrinti.aspx;
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="KayitAyrinti.aspx.cs" Inherits="gop.KayitAyrinti" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style2 {
height: 23px;
width: 217px;
}
.auto-style1 {
height: 23px;
width: 271px;
}
.degistir-button {
background:#7ab752;
margin:1px auto 0px;
text-align:right;
color:#FFF;
/*border:none;
border-top-left-radius:4px;
border-bottom-left-radius:4px;*/
-webkit-transition:background 0.5s;
}
.degistir-button:hover {
background:#DC3F42 #81c356;
}
.kaydet-button {
background:#7ab752;
margin:auto;
margin-right:4px;
margin-left:60px;
text-align:right;
color:#FFF;
/* border:none;
border-top-left-radius:40px;
border-bottom-left-radius:40px;
*/
-webkit-transition:background 0.5s;
}
.kaydet-button:hover {
background:#DC3F42 #81c356;
}
</style>
</head>
<body>
<center><asp:Image ID="Banner" runat="server" ImageUrl="images/logo.png" Height="88px" Width="509px"></asp:Image></center>
<form id="register" runat="server">
<br />
<div>
<table align="center">
<tr>
<td class="auto-style1" >
<asp:Label ID="lbl_ayrintiYetkiliAdSoyad" runat="server" Text="Yetkili Adı Soyad :" Font-Bold="True" Font-Names="Book Antiqua" ></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiYetkiliAdSoyad_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ayrintiGorusmeYapilanOkul" runat="server" Text="Görüşme Yapılan Okul :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:RadioButtonList ID="RadioButtonList_ayrintiGorusmeYapilanOkul" runat="server" Width="174px">
<asp:ListItem>Seyrantepe Şube 1</asp:ListItem>
<asp:ListItem>Seyrantepe Şube 2</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ayrintiveliAdSoyad" runat="server" Text="Veli Adı Soyadı :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiVeliAdiSoyadi_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_veliTel" runat="server" Text="Veli Telefon Numarası :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiVeliTel_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ikametAdres" runat="server" Text="İkamet Adresi :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<textarea id="ayrintiIkametAdres_txt" rows="5" cols="26" runat="server"></textarea>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ogrenciAdSoyad" runat="server" Text="Öğrenci Adı Soyadı :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiOgrenciAdSoyad_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ogrenciTel" runat="server" Text="Öğrenci Telefon Numarası :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiOgrenciTel_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_ilgilendigiBolum" runat="server" Text="İlgilendiği Bölüm :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:RadioButtonList ID="RadioButtonList_ayrintiIlgilendigiBolum" runat="server" Width="174px">
<asp:ListItem>Hemşire Yardımcılığı</asp:ListItem>
<asp:ListItem>Sağlık Bakım Teknisyenliği</asp:ListItem>
<asp:ListItem>Anadolu Lisesi</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_verilenFiyat" runat="server" Text="Verilen Fiyat :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiVerilenFiyat_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_gorusmeSonucu" runat="server" Text="Görüşme Sonucu :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="ayrintiGorusmeSonucu_txt" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="lbl_gorusmeNotlari" runat="server" Text="Görüşme Notları :" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<textarea id="ayrintiGorusmeNotlari_txt" rows="5" cols="26" runat="server"></textarea>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label1" runat="server" Text="" Font-Bold="True" Font-Names="Book Antiqua"></asp:Label>
</td>
<td class="auto-style2">
<asp:button id="degistir" runat="server" text="Değiştir" class="degistir-button" OnClick="degistir_Click"/>
<asp:Button ID="kaydet" runat="server" Text="Kaydet" CssClass="kaydet-button" OnClick="kaydet_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
This class is which shows values and try to update with degistir_Click,
KayitAyrinti.aspx.cs;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace gop
{
public partial class KayitAyrinti : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["kullanici"] != null)
{
Response.Write("Hoşgeldiniz..." + Session["kullanici"]);
Response.Redirect("KayitAyrinti.aspx");
}
else
{
// Response.Write("Giriş Yapınız.");
}
string connectionString = "xxx;Database=xxx;Uid=xxxx;Pwd=xxx;";
using (MySqlConnection cn = new MySqlConnection(connectionString))
{
string[] keys = Request.QueryString.GetValues("id");
String id = keys[0];
MySqlCommand cmd = new MySqlCommand("select id, yetkiliAdSoyad,gorusmeYapilanOkul,veliAdSoyad, veliTel, ikametAdres, ogrenciAdSoyad, ogrenciTel, ilgilendigiBolum,verilenFiyat,gorusmeSonucu,gorusmeNotlari from Kayitlar where id=" + id + "", cn);
try
{
cn.Open();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ayrintiYetkiliAdSoyad_txt.Text = (reader["yetkiliAdSoyad"].ToString());
RadioButtonList_ayrintiIlgilendigiBolum.SelectedValue = (reader["gorusmeYapilanOkul"].ToString());
ayrintiVeliAdiSoyadi_txt.Text = (reader["veliAdSoyad"].ToString());
ayrintiVeliTel_txt.Text = (reader["veliTel"].ToString());
ayrintiIkametAdres_txt.InnerText = (reader["ikametAdres"].ToString());
ayrintiOgrenciAdSoyad_txt.Text= (reader["ogrenciAdSoyad"].ToString());
ayrintiOgrenciTel_txt.Text = (reader["ogrenciTel"].ToString());
RadioButtonList_ayrintiIlgilendigiBolum.SelectedValue= (reader["ilgilendigiBolum"].ToString());
ayrintiVerilenFiyat_txt.Text= (reader["verilenFiyat"].ToString());
ayrintiGorusmeSonucu_txt.Text= (reader["gorusmeSonucu"].ToString());
ayrintiGorusmeNotlari_txt.InnerText = (reader["gorusmeNotlari"].ToString());
}
}
}
catch (Exception ex)
{
}
}
}
protected void degistir_Click(object sender, EventArgs e)
{
string connectionString = "Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx;";
using (MySqlConnection cn = new MySqlConnection(connectionString))
{
string[] keys = Request.QueryString.GetValues("id");
String id = keys[0];
cn.Open();
MySqlCommand komut = new MySqlCommand("UPDATE Kayitlar SET yetkiliAdSoyad=#ayrintiYetkiliAdSoyad, gorusmeYapilanOkul = #ayrintiGorusmeYapilanOkul,"+
" veliAdSoyad = #ayrintiVeliAdSoyad ,veliTel = #ayrintiVeliTel,ikametAdres = #ayrintiIkametAdres ,ogrenciAdSoyad = #ayrintiOgrenciAdSoyad, " +
"ogrenciTel=#ayrintiOgrenciTel,ilgilendigiBolum = #ayrintiIlgilendigiBolum,verilenFiyat=#ayrintiVerilenFiyat,gorusmeSonucu=#ayrintiGorusmeSonucu,gorusmeNotlari=#ayrintiGorusmeNotlari", cn);
komut.Parameters.AddWithValue("#ayrintiYetkiliAdSoyad", ayrintiYetkiliAdSoyad_txt.Text);
komut.Parameters.AddWithValue("#ayrintiGorusmeYapilanOkul", RadioButtonList_ayrintiGorusmeYapilanOkul.SelectedValue);
komut.Parameters.AddWithValue("#ayrintiVeliAdSoyad", ayrintiVeliAdiSoyadi_txt.Text);
komut.Parameters.AddWithValue("#ayrintiVeliTel", ayrintiVeliTel_txt.Text);
komut.Parameters.AddWithValue("#ayrintiIkametAdres", ayrintiIkametAdres_txt.InnerText);
komut.Parameters.AddWithValue("#ayrintiOgrenciAdSoyad", ayrintiOgrenciAdSoyad_txt.Text);
komut.Parameters.AddWithValue("#ayrintiOgrenciTel", ayrintiOgrenciTel_txt.Text);
komut.Parameters.AddWithValue("#ayrintiIlgilendigiBolum", RadioButtonList_ayrintiIlgilendigiBolum.SelectedValue);
komut.Parameters.AddWithValue("#ayrintiVerilenFiyat", ayrintiVerilenFiyat_txt.Text);
komut.Parameters.AddWithValue("#ayrintiGorusmeSonucu", ayrintiGorusmeSonucu_txt.Text);
komut.Parameters.AddWithValue("#ayrintiGorusmeNotlari", ayrintiGorusmeNotlari_txt.InnerText);
komut.ExecuteNonQuery();
Response.Redirect("KayitGoruntule.aspx");
komut.Dispose();
}
}
protected void kaydet_Click(object sender, EventArgs e)
{
}
}
}
The textboxes on your form are being populated with their database defaults in the Page_Load event. This is fine the first time through; however, when you click your 'degistir' button, a "postback" occurs, and Page_Load fires again and repopulates those defaults, losing whatever changes were submitted. Keep in mind that Page_Load fires before any control click events.
To fix this, you need to check for IsPostback in Page_Load to prevent your loader from firing on the update. If IsPostback is true, inhibit the load of the defaults from your database. This, in turn, should allow the update to occur with the updated data provided on your form. Something along these lines:
// code snipped...
if (Session["kullanici"] != null)
{
Response.Write("Hoşgeldiniz..." + Session["kullanici"]);
Response.Redirect("KayitAyrinti.aspx");
}
else
{
// Response.Write("Giriş Yapınız.");
}
if (!IsPostback) // <-- Add this check
{
string connectionString = "xxx;Database=xxx;Uid=xxxx;Pwd=xxx;";
using (MySqlConnection cn = new MySqlConnection(connectionString))
{
string[] keys = Request.QueryString.GetValues("id");
/// rest of code snipped
Also, be sure to modify your UPDATE statement to include a WHERE clause that limits the UPDATE to only that record with the desired ID. As it is, ALL your records will be updated!

Use ModalPopupExtender with datalist and collection pager

I have a search button in my page. When I click the button, a paged datalist will show up
with result. I want to use modalPopupExtender with Datalist and collection pager. Is it possible ? Here is the code i tried but it doesn't work :
<asp:Label ID="Label5" runat="server"></asp:Label>
<asp:ModalPopupExtender ID="Label1_ModalPopupExtender" runat="server" CancelControlID="btThoat"
DynamicServicePath="" Enabled="True" PopupControlID="Panel1" TargetControlID="Label5">
</asp:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server">
<div style="margin-left: 20px; padding-top: 50px">
<asp:Label ID="lbl_CS" runat="server" Text="Ca sĩ" ForeColor="#FF33CC" Font-Size="18"
Visible="True"></asp:Label>
<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" CellPadding="4" GridLines="Both" RepeatColumns="4"
OnItemDataBound="DataList1_ItemDataBound">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<ItemStyle BackColor="White" ForeColor="#330099" />
<ItemTemplate>
<table>
<tr>
<td style="width: 10px">
<asp:RadioButton ID="rd_CS" runat="server" GroupName="Casi" Text='<%# Eval("MaCS")%>'
AutoPostBack="False"></asp:RadioButton>
</td>
<td style="width: 75px">
<asp:Image ID="Img_Casi" runat="server" ImageUrl='<%#Eval("Hinhanh")%>' Width="75px"
Height="75px" BorderColor="#66FF33" />
</td>
<td style="width: 50px">
<asp:Label ID="lbl_Ten" runat="server" Text='<%#Eval("TenCS")%>'></asp:Label>
</td>
<td style="width: 40px">
<asp:Label ID="lbl_Ngaysinh" runat="server" Text='<%#Eval("Ngaysinh")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
</asp:DataList>
<cc2:CollectionPager ID="CollectionPager1" runat="server" MaxPages="1000" PagingMode="QueryString"
BackNextDisplay="Buttons" QueryStringKey="Datalist1">
</cc2:CollectionPager>
</div>
</asp:Panel>
Code in c#:
bool Checkcs()
{
string cs = "select MaCS, Quocgia, TenCS, Hinhanh, Thongtin, cast(convert(char(11), Ngaysinh, 113) as char) as Ngaysinh from casi where tencs like N'%" + txt_CS.Text + "%'";
da = new SqlDataAdapter(cs, cnn);
dtSP = new DataTable();
cnn.Open();
da.Fill(dtSP);
cnn.Close();
CollectionPager1.PageSize = 8;
CollectionPager1.DataSource = dtSP.DefaultView;
CollectionPager1.BindToControl = DataList1;
DataList1.DataSource = CollectionPager1.DataSourcePaged;
DataList1.DataBind();
Label1_ModalPopupExtender.Show();
if (dtSP.Rows.Count != 0)
return true;
else
return false;
}
protected void img_CheckCS_Click(object sender, ImageClickEventArgs e)
{
Checkcs();
}
If it's impossible. Is there another way to do it ? If it's possible. Can you show me an example code ? Any help would be great.
This is Sample. Please refer with this
.modalBackground {
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}
.modalPopupCss {
background-color: white;
border-width: 1px;
border-style: solid;
border-color: #0066B3;
padding: 3px;
}
ASPX
<div>
<asp:ModalPopupExtender BackgroundCssClass="modalBackground" ID="Label1_ModalPopupExtender" CancelControlID="Button2" runat="server" Enabled="True" PopupControlID="Panel1" TargetControlID="lbl_CS"></asp:ModalPopupExtender>
<asp:Panel ID="Panel1" CssClass="modalPopupCss" runat="server">
<div style="margin-left: 20px; padding-top: 50px">
<asp:Label ID="lbl_CS" runat="server" Text="" ForeColor="#FF33CC" Font-Size="18" Visible="True"></asp:Label>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
<asp:Button ID="Button2" runat="server" Text="Close" />
</div>
</asp:Panel>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />
Aspx.Cs
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("State");
}
protected void Button1_Click(object sender, EventArgs e)
{
dt.Rows.Add("1", "Vignesh", "True");
GridView1.DataSource = dt;
GridView1.DataBind();
Label1_ModalPopupExtender.Show();
}

How to select a value from a row in a gridview to use as a variable in a new stored procedure?

The thought is that the user searches the db for a record. When the records return they can click on a record to return more information from anther table. Thanks
Here's my code:
This contains my c# logic.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Globalization;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public DataSet GetDataSource()
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("SERVER=ServerName;Trusted_Connection=Yes;DATABASE=DBName"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "customerSearchStoredProc";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#lName", lNameTextbox.Text);
cmd.Parameters.AddWithValue("#fName", fNameTextbox.Text);
//cmd.Parameters.AddWithValue("#State", State);
//cmd.Parameters.AddWithValue("#Zip", Zip);
cmd.Connection = con;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(ds);
return ds;
}
}
}
public DataSet GetSpecificCustomerData(string cusId)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("SERVER=serverName;Trusted_Connection=Yes;DATABASE=dbName"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "getCustomerRecords";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#cusId", cusId);
cmd.Connection = con;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(ds);
return ds;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds;
ds = GetDataSource();
GridView1.PageIndex = 0;
if (ds.Tables != null)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = GetDataSource();
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
DataSet ds;
string customerID =;
customerID = GridView1.SelectedRow.Cells[0].Text;
ds = GetSpecificCustomerData(customerID);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
Here's my aspx page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %>
<%# OutputCache Duration="1" VaryByParam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MSS Archive Page</title>
</head>
<body style="text-align: left">
<form id="form1" runat="server">
<span style="font-size: 24pt; color: #0000cc; font-family: Euphemia"><strong>
MSS Archiver </strong></span><table style="width: 1056px; height: 106px">
<tr>
<td style="width: 159px; height: 72px">
<asp:Label ID="Label1" Text="Last Name" runat="server" />
<asp:TextBox ID="lNameTextbox" runat="server"></asp:TextBox></td>
<td style="width: 176px; height: 72px">
<asp:Label ID="Label2" Text="First Name" runat="server" />
<asp:TextBox ID="fNameTextbox" runat="server" ></asp:TextBox></td>
<td style="width: 157px; height: 72px">
<asp:Label ID="Label5" Text="State" runat="server" />
<asp:TextBox ID="StateTextbox" runat="server" ReadOnly="True">MA</asp:TextBox></td>
<td style="width: 178px; height: 72px">
<asp:Label ID="Label6" Text="Zip" runat="server" /><asp:TextBox ID="Zip" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 159px">
</td>
<td style="width: 176px">
</td>
<td style="width: 157px">
</td>
<td style="width: 178px; text-align: center">
<asp:Button ID="Button1" runat="server" PostBackUrl="~/Default.aspx" Text="Search" OnClick="Button1_Click" /></td>
</tr>
</table>
<table style="width: 1086px">
<tr>
<td>
</td>
<td style="text-align: center">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateSelectButton="True" OnPageIndexChanging="GridView1_PageIndexChanging" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" >
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
Set your gridview's DataKeys property to your primary key field in your dataset
DataKeys="<YourPrimaryKeyField>"
Set your grid view's OnSelectedIndexChanged property to gridView_SelectedIndexChanged
Add a method in your code behind to handle the event.
protected void gridView_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
{
string key = gridView.DataKeys[e.NewSelectedIndex].Value.ToString();
//Call your GetData function and pass in this value as a parameter
GetSpecificCustomerData(key) ;
}
U are better of using AutoGenerateColumns=false, BoundFields/Templatefields and rowcommand event.
sample here

paging in gridview get same data for all pages

I had gridview which get data from database according to two event .The first from method ,the second when selected ddl.it worked well ,I made paging and when I go through paging pages I must click two click on number of page to go to this page also all pages get same data for firt page .So plaes any one help me.
<aspx>
<div class="div_open_CS m10 ad_mun_font">
<table width="560" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td class="pag_bor">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="Pag_toparow">
</td>
<td class="Pag_hedfont">
Dealers list
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="pag_bor">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="ad_mun_font_h" width="100">
Select City
</td>
<td>
<asp:SqlDataSource ID="SDSGetDealerArea" runat="server" ConnectionString="<%$ ConnectionStrings:ElarabyGroup %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [AREA_ID], [AREA_ENG] FROM [DealerArea]">
</asp:SqlDataSource>
<%-- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>--%>
<asp:DropDownList CssClass="ad_mun_font_h" ID="DDlCity" runat="server" AutoPostBack="True"
DataSourceID="SDSGetDealerArea" DataTextField="AREA_ENG" DataValueField="AREA_ID"
OnDataBound="DDlCity_DataBound" OnSelectedIndexChanged="DDlCity_SelectedIndexChanged">
</asp:DropDownList>
<%-- </ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DDlCity" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>--%>
</td>
<td>
<asp:Label ID="LblResult" runat="server" Text="Result" Font-Bold="True" ForeColor="#006699"
Visible="false"></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" class="tm10 rm10">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None"
CellPadding="3" DataKeyNames="DEALER_ID,LOC_ID,CAT_ID,AREA_ID" CellSpacing="3"
GridLines="Horizontal" Width="510px" BorderWidth="1px" OnPageIndexChanging="GridView1_PageIndexChanging">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Name" SortExpression="NAME_ENG">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("NAME_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("NAME_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="ADR_ENG">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ADR_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ADR_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Telephone" SortExpression="TEL_ENG">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("TEL_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("TEL_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" SortExpression="TEL_ARA">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("TEL_ARA") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("TEL_ARA") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="LOC_ENG">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("LOC_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("LOC_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category" SortExpression="CAT_NAME">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("CAT_NAME") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("CAT_NAME") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Area" SortExpression="AREA_ENG">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("AREA_ENG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("AREA_ENG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
<asp:Panel ID="pnlModal" runat="server" Style="display: none" CssClass="modalPopup">
Our Valued Customer You Are Not Registered Are You Want To Register?
<br />
<br />
<br />
<br />
<table id="LoginTL" runat="server" width="300" border="0" align="center" cellpadding="0"
cellspacing="2" visible="true" style="border-color: #666666">
<tr>
<td width="80px" class="bod_d_reg_txt_p lm7">
Username :
</td>
<td>
<label>
<asp:TextBox ID="TxtUser" runat="server" Width="125px"></asp:TextBox>
</label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="TxtUser" Display="Dynamic" SetFocusOnError="True">*</asp:RequiredFieldValidator>
</td>
<td>
<table width="110" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<label>
<asp:CheckBox ID="CBRemeber" runat="server" class="tx_s" OnCheckedChanged="CBRemeber_CheckedChanged" />
</label>
</td>
<td class="bod_d_reg_txt_w">
Remember me
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="80" class="bod_d_reg_txt_p lm7">
Password :
</td>
<td>
<label>
<asp:TextBox ID="TXTPassword" runat="server" TextMode="Password" Width="125px"></asp:TextBox>
</label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
ControlToValidate="TXTPassword" Display="Dynamic" SetFocusOnError="True">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:ImageButton ID="IBLogin" runat="server" ImageUrl="images/home-d_login.jpg" OnClick="IBLogin_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" CssClass="ad_mun_font" Text="result" Visible="false"></asp:Label>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Close
</td>
<td>
</td>
<td>
Register
</td>
</tr>
</table>
<br />
</asp:Panel>
<cc1:ModalPopupExtender TargetControlID="btnYes" ID="pnlModal_ModalPopupExtender"
runat="server" Enabled="True" BackgroundCssClass="modalBackground" PopupControlID="pnlModal"
CancelControlID="btnYes" DropShadow="true">
</cc1:ModalPopupExtender>
<asp:HiddenField ID="btnYes" runat="server" />
</td>
</tr>
</table>
</div>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridFunction();
}
}
private void BindGridFunction()
{
DataTable DT = new DataTable();
using (SqlConnection con = Connection.GetConnection())
{
SqlCommand Com = new SqlCommand();
if (DDlCity.SelectedIndex < 0)
{
Com = new SqlCommand("GetDealers", con);
Com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter DA = new SqlDataAdapter(Com);
DA.Fill(DT);
GridView1.DataSource = DT;
GridView1.DataBind();
}
else
{
Com = new SqlCommand("GetDealersByArea", con);
Com.CommandType = CommandType.StoredProcedure;
Com.Parameters.Add(Parameter.NewNVarChar("#AREA_ENG", DDlCity.SelectedItem.Text));
SqlDataAdapter DA = new SqlDataAdapter(Com);
DA.Fill(DT);
GridView1.DataSource = DT;
GridView1.DataBind();
}
}
}
protected void DDlCity_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridFunction();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
}
Try rebinding after GridView1.PageIndex = e.NewPageIndex; call GridView1.DataBind();
.
--EDIT--
DataSet and then DataBind(), try it like:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridFunction();
}

Categories

Resources