2014年7月13日 星期日

[RESOLVED] hyperlink in gridview


hi there,


my site is using a gridview including a hyperlink column (select)


this works fine if you click select, all data located in that row will be transformed to a next page at the right spot; everything ok.


But if my gridview generates a number of rows, the following hyperlinks are not working, it shows only the 'select' text


but it is not click-able. The strange thing is that it worked fine the first time i build it.


what goes wrong in here?  it can't be a big thing


kind regards


Romano


            Width="1150px" AllowPaging="True" PageSize="14"
onpageindexchanging="GV_PageIndexChanging" AllowSorting="True"
BorderColor="#109DAA" BorderStyle="Solid" BorderWidth="2px">



ShowHeader="False" SortExpression="IMAGE">

Font-Underline="False" ForeColor="#109DAA" BorderColor="#109DAA"
BorderStyle="Solid" BorderWidth="2px" />
Width="60px" CssClass="GVstyle" />


Font-Underline="False" ForeColor="#109DAA" BorderColor="#109DAA"
BorderStyle="Solid" BorderWidth="2px" />
CssClass="GVstyle" Wrap="True" />


Font-Underline="False" ForeColor="#109DAA" BorderColor="#109DAA"
BorderStyle="Solid" BorderWidth="2px" />



Font-Underline="False" ForeColor="#109DAA" BorderColor="#109DAA"
BorderStyle="Solid" BorderWidth="2px" />



Font-Underline="False" ForeColor="#109DAA" BorderColor="#109DAA"
BorderStyle="Solid" BorderWidth="2px" />


DataNavigateUrlFormatString="outputpage.aspx?IMAGE={0}&NAME={1}&CITY={2}&PROFESSION={3}&CATEGORY={4}&GENDER={5}&AGE={6}&STATES={7}&TELEPHONE={8}&EMAIL={9}&EMPLOYER={10}&YEARS={11}&EDUCATION={12}&MOTIVATION={13}&INFORMATION={14}"
Text="Select" >







Code behind


protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
DataBind();
}
}

private void BindData()
{
string connstr = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);

DataSet DS = new DataSet();
DataTable members = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand SelectCommand = new SqlCommand();
SelectCommand.CommandType = CommandType.Text;

SelectCommand.CommandText = "SELECT NAME,GENDER,AGE,STATES,CITY,TELEPHONE,EMAIL,CATEGORY,PROFESSION,EMPLOYER,YEARS,EDUCATION,MOTIVATION,INFORMATION,IMAGE FROM members WHERE STATES = @STATES AND CATEGORY = @CATEGORY ";
SelectCommand.Connection = conn;

SelectCommand.Parameters.Add("@STATES",SqlDbType.VarChar).Value = DropDownList7.SelectedItem.Text;
SelectCommand.Parameters.Add("@CATEGORY",SqlDbType.VarChar).Value = DropDownList8.SelectedItem.Text;

da.SelectCommand = SelectCommand;
da.Fill(DS);
GV.DataSource = DS;
GV.DataBind();

if (GV.Rows.Count == 0)
{
errormessage.Text = "there are no members to be found, please try it again later";
}
if (GV.Rows.Count > 0)
{
errormessage.Text = "";
}

conn.Close();

}

protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GV.PageIndex = e.NewPageIndex;
BindData();
}

protected void Button10_Click(object sender, EventArgs e)
{

BindData();
}

}



Usually, HyperLinkField not clickable because DataNavigateUrlFields has null value, check the data. Why not simply passing id value and get another values in another page based this id?

沒有留言:

張貼留言