0
Answer

Grid View Page index click problem(same page load every time

Rajesh Kumar

Rajesh Kumar

10y
606
1
Hi,
This my whole code..
////////////
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
public partial class Admin_deletescore : System.Web.UI.Page
{
string username = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["UserName"] != null)
{
username = Convert.ToString(Session["UserName"]);
lblUser.Text = "Welcome" + ' ' + username;
}
else
{
Response.Redirect("login.aspx");
}
bindTournament();
bindRecentMatches();
}
}
private void bindTournament()
{
try
{
string str = "select_t_by_organizer_name";
SqlConnection objCon;
SqlCommand objCmd;
DataSet objDs = new DataSet();
SqlDataAdapter objDa;
using (objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sports"].ToString()))
{
objCon.Open();
using (objCmd = new SqlCommand(str, objCon))
{
if (username == "vipin")
{
GetTournament();
}
else
{
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.AddWithValue("@eventorganizer", Convert.ToString(Session["UserName"]));
using (objDa = new SqlDataAdapter(objCmd))
{
objDa.Fill(objDs);
if (objDs.Tables[0].Rows.Count > 0)
{
if (grdlistTeam != null)
{
ddlComp.DataSource = objDs.Tables[0].DefaultView;
ddlComp.DataTextField = "tname";
ddlComp.DataValueField = "tid";
ddlComp.DataBind();
ddlComp.Items.Insert(0, new ListItem("Select Tournament"));
}
}
else
{
}
}
}
}
}
}
catch (Exception ex)
{
}
}
private void GetTournament()
{
SqlConnection objCon;
SqlCommand objCmd;
string strQuery;
DataSet objDs = new DataSet();
SqlDataAdapter objDa;
int i = 0;
try
{
strQuery = "select * from tdescription order by TDescription.TStartDate ASC";
using (objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sports"].ToString()))
{
objCon.Open();
using (objCmd = new SqlCommand(strQuery, objCon))
{
using (objDa = new SqlDataAdapter(objCmd))
{
i = objDa.Fill(objDs);
if (i > 0)
{
ddlComp.DataSource = objDs;
ddlComp.DataTextField = "TName";
ddlComp.DataValueField = "TtId";
ddlComp.DataBind();
ddlComp.Items.Insert(0, new ListItem("--Select Tournament--", "0"));
}
}
}
}
}
catch (Exception ex)
{
Exceptionhandle exception = new Exceptionhandle();
exception.Exceptionhandle1(ex.ToString());
}
}
private void bindRecentMatches()
{
SqlConnection objCon;
SqlCommand objCmd;
string strQuery;
DataSet objDs = new DataSet();
SqlDataAdapter objDa;
int i = 0;
try
{
strQuery = "select_recent_match_by_eventorganizer";
using (objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sports"].ToString()))
{
objCon.Open();
using (objCmd = new SqlCommand(strQuery, objCon))
{
objCmd.CommandType = CommandType.StoredProcedure;
//objCmd.Parameters.AddWithValue("@eventorganizer", username);
objCmd.Parameters.AddWithValue("@eventorganizer", Convert.ToString(Session["UserName"]));
using (objDa = new SqlDataAdapter(objCmd))
{
// try {
i = objDa.Fill(objDs);
if (objDs.Tables[0].Rows.Count > 0)
{
if (grdlistTeam != null)
{
grdlistTeam.DataSource = objDs.Tables[0].DefaultView;
grdlistTeam.DataBind();
}
}
else
{
}
//} catch (Exception ej) { throw ej; }
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void grdlistTeam_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
try
{
if (e.Row.RowType != DataControlRowType.Header)
{
foreach (TableCell cell in e.Row.Cells)
cell.Attributes.Add("Style", "border-bottom:5px solid #e1dfe0;");
}
Label lblDate = (Label)e.Row.FindControl("lbldate");
string dtCust = ConvertToDate(lblDate.Text);
lblDate.Text = dtCust;
Label lblResult = (Label)e.Row.FindControl("lblResult");
if (lblResult.Text.Length > 35)
{
lblResult.ToolTip = lblResult.Text;
lblResult.Text = lblResult.Text.Substring(0, 35) + "..";
}
else
{
lblResult.Text = lblResult.Text;
lblResult.ToolTip = lblResult.Text;
}
LinkButton lnkFirstTeam = (LinkButton)e.Row.FindControl("lnkFirstTeam");
if (lnkFirstTeam.Text.Length > 15)
{
lnkFirstTeam.ToolTip = lnkFirstTeam.Text;
lnkFirstTeam.Text = lnkFirstTeam.Text.Substring(0, 15) + "..";
}
else
{
lnkFirstTeam.Text = lnkFirstTeam.Text;
lnkFirstTeam.ToolTip = lnkFirstTeam.Text;
}
LinkButton lnkSecondTeam = (LinkButton)e.Row.FindControl("lnkSecondTeam");
if (lnkSecondTeam.Text.Length > 15)
{
lnkSecondTeam.ToolTip = lnkSecondTeam.Text;
lnkSecondTeam.Text = lnkSecondTeam.Text.Substring(0, 15) + "..";
}
else
{
lnkSecondTeam.Text = lnkSecondTeam.Text;
lnkSecondTeam.ToolTip = lnkSecondTeam.Text;
}
LinkButton lnkTournament = (LinkButton)e.Row.FindControl("lnkTournament");
if (lnkTournament.Text.Length > 9)
{
lnkTournament.ToolTip = lnkTournament.Text;
lnkTournament.Text = lnkTournament.Text.Substring(0, 9) + "..";
}
else
{
lnkTournament.Text = lnkTournament.Text;
lnkTournament.ToolTip = lnkTournament.Text;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
public static string ConvertToDate(string DateString)
{
string[] strArr = DateString.Split('-');
string strMM = strArr[0];
string strDD = strArr[1];
string strYYYY = strArr[2];
DateString = strDD + " " + strMM + "," + strYYYY;
return DateString;
}
protected void grdlistTeam_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdlistTeam.PageIndex = e.NewPageIndex;
bindRecentMatches();
}
protected void ddlComp_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
// string str = "select * from currentmatch where tid=@tid order by EventDate ASC";
string str = "select * from currentmatch where tid=@tid";
SqlConnection objCon;
SqlCommand objCmd;
DataSet objDs = new DataSet();
SqlDataAdapter objDa;
using (objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sports"].ToString()))
{
objCon.Open();
using (objCmd = new SqlCommand(str, objCon))
{
objCmd.CommandType = CommandType.Text;
objCmd.Parameters.AddWithValue("@tid", Convert.ToInt32(ddlComp.SelectedValue));
using (objDa = new SqlDataAdapter(objCmd))
{
objDa.Fill(objDs);
if (objDs.Tables[0].Rows.Count > 0)
{
grdlistTeam.DataSource = objDs.Tables[0].DefaultView;
grdlistTeam.DataBind();
}
else
{
grdlistTeam.EmptyDataText = "No record found";
grdlistTeam.DataBind();
}
}
}
}
}
catch (Exception ex)
{
}
}
}
 
Thanks in advance.