using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
publicpartialclass DevRnD_Datacontrol : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
binddata();
}
// Function to bind data in data controls..publicvoid binddata()
{
string str ="Data Source=VS-NAVINCHANDRA\\SQLEXPRESS;Initial Catalog=dbNavin;Integrated Security=SSPI"; // your connection string here SqlConnection con =new SqlConnection(str);
DataSet ds =new DataSet();
SqlDataAdapter da =new SqlDataAdapter("getCompNews", con); // name of your stored procedure, da.Fill(ds);
ds.Relations.Add("InnerVal", ds.Tables[0].Columns["compname"], ds.Tables[1].Columns["compname"]); // making a relation between two tables. GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
// Bind url for more button...protectedvoid GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink lnkMore = (HyperLink)e.Row.FindControl("link");
Label lbl=(Label)e.Row.FindControl("Label1");
lnkMore.NavigateUrl ="~/Company.aspx?cmp="+lbl.Text;
}
}
}
SQL code
CreateProcedure[dbo].[getCompNews]asbegincreatetable #Temp
(
compname varchar(50),
news varchar(150)
)
Insertinto #Tempselect a.compname, b.news from Company as a
innerjoin CompNews as b on a.CompId=b.CompId orderby compname
Selectdistinct compname from #Tempselect*from #Tempenddroptable #Temp
ListItem myListItem = SearchType.SelectedItem;
ListItem crItem =null;
String searchText = TextBox1.Text;
if(myListItem.Value =="Name")
{
if(TextBox1.Text !="")
{
String searchSubfir = searchText.Substring(0,1);
String searchSubsec = searchText.Substring(1);
searchText = searchSubfir.ToUpper()+searchSubsec.ToLower();
// Search by country or region name. crItem = ItemCollection.FindByText(searchText);
}
}
else
{
// Search by country or region code. crItem = ItemCollection.FindByValue(searchText.ToUpper());
}
String str ="Search is successful. Match is Found.<br />";
str =str +"The results for search string '"+ searchText +"' are:<br />";
str = str +"the country or region code is "+ crItem.Value +"<br />";
str = str +"the country or region name is "+ crItem.Text;
// Add the string to the label.Label1.Text = str;
PrivateSub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) HandlesMyBase.Load
btnSave.Attributes.Add("onclick", "DisableButton()")
End SubPrivateSub btnSave_Click(ByVal sender AsObject, _
ByVal e As System.EventArgs) Handles btnSave.Click
System.Threading.Thread.Sleep(5000)
Response.Write("Page has been saved.")
End Sub