Hello rayan , this is the code for my grid :
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bool boolAdmin = (bool)Session["admin"];
bool boolWebMaster = (bool)Session["webMaster"];
if (boolAdmin)
{
if (!IsPostBack)
{
Session["Sorting"] = "ASC";
Session["ObjToSortBy"] = "ID";
Literal1.Text = "";
tbSVSearch.Focus();
string[] strSelection = { "1", "2", "3", "4" };
ddlSelection.DataSource = strSelection;
ddlSelection.DataBind();
ddlSelection.DataSource = strSelection;
ddlSelection.DataBind();
string[] strSeach = {"UL", "Date", "Last Name"};
ddlSeach.DataSource = strSeach;
ddlSeach.DataBind();
if (boolWebMaster)
{
Literal1.Text = @"If you want to edit/delete a log visit the <a href='../webMaster/Default.aspx'> Webmaster</a> part of the site";
}
}
}
else
{
Response.Redirect(@"~\Default.aspx"); }
}
private void dataBind(string strQuery)
{
sql mySqlQuery = new sql();
DataTable dt = mySqlQuery.queryDbReturnDt(strQuery, ref lblResultsError);
GridView1.DataSource = dt;
GridView1.DataBind();
if (dt.Rows.Count == 0)
{
GridView1.Visible = false;
lblResultsError.Text = "Your search did not mach any records. ";
}
else
{
lblResultsError.Text = "";
GridView1.Visible = true;
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
Label lblID = row.FindControl("Label1") as Label;
Label lblUL = row.FindControl("Label2") as Label;
Session["myID"] = lblID.Text;
Session["myUl"] = lblUL.Text;
string strFullname = Session["userFname"].ToString() + " " + Session["userLname"].ToString();
DateTime today = DateTime.Now;
string strDateLastViewed = today.ToString();
sql mySqlQuery = new sql();
mySqlQuery.queryDbVoid("UPDATE USED_LOG SET LAST_VIEWED_BY = '" + strFullname + "', DATE_LAST_VIEWED = '" + strDateLastViewed + "' WHERE (" + "UL = '" + lblUL.Text + "') AND " + "(ID = '" + lblID.Text + "')", ref lblResultsError);
Response.Redirect("summary.aspx");
}//END GridView1_SelectedIndexChanged
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
dataBind(Session["myQuery"].ToString());
}
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" PageSize="15" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True" >
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EBEBEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#0A4A13" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#0A4A13" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UL">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("UL") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("UL") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LAST_NAME" HeaderText="Last N" SortExpression = "LAST_NAME" />
<asp:BoundField DataField="FIRST_NAME" HeaderText="First N" SortExpression = "FIRST_NAME"/>
<asp:BoundField DataField="DATE" HeaderText="Date Registered" SortExpression = "DATE"/>
</Columns>
</asp:GridView>