olootu
asked on
Get Values from a LinkButton
Hi all,
I am querying a database to get some addresses. If my query returns more than one address result, I would display the results and ask user to click on the one appropriate to them. I would then use the value of the ckicked link for my further queries of other database tables.
Looking at the code below, how would I get the value of the Linkbutton (link) when clicked and then use this value on the same page?
I am querying a database to get some addresses. If my query returns more than one address result, I would display the results and ask user to click on the one appropriate to them. I would then use the value of the ckicked link for my further queries of other database tables.
Looking at the code below, how would I get the value of the Linkbutton (link) when clicked and then use this value on the same page?
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Odbc;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Principal;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//check textbox is not empty
if (roads.Text.Length == 0)
{
notext.Text="Please enter your address or postcode";
}
else
{
notext.Text = "";
//connect to the mysql db using the connection string in the web.config
string Authority_cccConnection = ConfigurationManager.ConnectionStrings["myconnectionstring"].ToString();
string Authority_gisConnection = ConfigurationManager.ConnectionStrings["myconnectionstring"].ToString();
string road = roads.Text;
string odbc_query = "SELECT DISTINCT road,schedule FROM waste_confirm WHERE road='" + road + "' OR postcode='" + road + "' ";
OdbcConnection myConnection = new OdbcConnection(Authority_cccConnection);
myConnection.Open();
OdbcCommand myCommand = new OdbcCommand(odbc_query, myConnection);
DataTable myDataTable = new DataTable();
OdbcDataAdapter mySQLDataAdapter = new OdbcDataAdapter(myCommand);
mySQLDataAdapter.Fill(myDataTable);
if (myDataTable.Rows.Count < 1)//if no data is returned.
{
notext.Text = "No data found, please try again";
}
else
{
if (myDataTable.Rows.Count > 1)
{
foreach (DataRow morethanoneaddress in myDataTable.Rows)
{
notext.Text = "More than one entry was found in our database. Please select your road from the list below:" + "<br />";
LinkButton link = new LinkButton();
link.Text = morethanoneaddress[0] + "<br />";
displays.Controls.Add(link);
}
}
}
GridView1.DataSource = myDataTable;
GridView1.DataBind();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER