C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




please give the code...its very urgent.....


Posted Date: 30 Aug 2008      Total Responses: 4

Posted By: ramya       Member Level: Gold     Points: 1


i need to bind data in gridview .then it will displayed within <div> tag while i click on the imagebutton in asp.net with c#...Please give me the code pls......



Responses

Author: Karthikeyan S    30 Aug 2008Member Level: GoldRating:     Points: 6
Hi,

Use '<%
//your dynamic page .aspx.vb or .aspx.cs code comes here
%>'

where ever in design page you want code like div tag, page title, table data / header cells etc.

in design page:

<div>'<%= mstrKRASortExpression %>' </div>

in code behind page:

private static string mstrAvailableQuarters = "Testing tag content";

in back end code make sure that the variable which is having dynamic database value must be public and so it should not be private or else and it must be declared module level that is out side of any sub-procedure or functions.

Store the dynamic value in local variable 'mstrAvailableQuarters ' and display it in div tag.



Author: Vidhya    30 Aug 2008Member Level: GoldRating:     Points: 6
hi,

binding the data in data controls. The code looks like this:

protected void Page_Load(object sender, EventArgs e)
{
binddata();
}

// Function to bind data in data controls..
public void binddata()
{
// your connection string here
string str = "Data Source=VS-NAVINCHANDRA\\SQLEXPRESS;" +
"Initial Catalog=dbNavin;Integrated Security=SSPI";
SqlConnection con = new SqlConnection(str);
DataSet ds = new DataSet();
// name of your stored procedure,
SqlDataAdapter da = new SqlDataAdapter("getCompNews", con);
da.Fill(ds);

ds.Relations.Add("InnerVal",
ds.Tables[0].Columns["compname"],
// making a relation between two tables.
ds.Tables[1].Columns["compname"]);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
On clicking the ‘More’ link button, it should redirect to page which shows all the news of that particular company. So, we have to set NavigateUrl property for this control dynamically. To do this, write the code given below. As I have passed company name in query string, you can very easily access the respective company data from your table to display.

protected void 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;
}
}
As I've mentioned, because I've used a stored procedure you must create a stored procedure that returns tables. If you don't want to create it, just copy and paste the stored procedure given below and compile it. Make sure that your database contains all tables and respective columns.

Create Procedure [dbo].[getCompNews]

as
begin
create table #Temp
(
compname varchar(50),
news varchar(150)
)

Insert into #Temp
select a.compname, b.news from Company as a

inner join CompNews as b on a.CompId=b.CompId order by compname


Select distinct compname from #Temp
select * from #Temp
end
drop table #Temp



Author: deepak    30 Aug 2008Member Level: GoldRating:     Points: 4
cal the function where u wan to bind the data
public void bind()
{
string str = " server=localhost;Data Source=xxx;" +
"uid=;pwd=;";
SqlConnection con = new SqlConnection(str);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command String, con);
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}


Author: Arun    30 Aug 2008Member Level: BronzeRating:     Points: 6
hey hi....

binding the data in data controls

protected void Page_Load(object sender, EventArgs e)
{
binddata();
}

// Function to bind data in data controls..
public void binddata()
{
// your connection string here
string str = "Data Source=VS-NAVINCHANDRA\\SQLEXPRESS;" +
"Initial Catalog=dbNavin;Integrated Security=SSPI";
SqlConnection con = new SqlConnection(str);
DataSet ds = new DataSet();
// name of your stored procedure,
SqlDataAdapter da = new SqlDataAdapter("getCompNews", con);
da.Fill(ds);

ds.Relations.Add("InnerVal",
ds.Tables[0].Columns["compname"],
// making a relation between two tables.
ds.Tables[1].Columns["compname"]);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
On clicking the ‘More’ link button, it should redirect to page which shows all the news of that particular company. So, we have to set NavigateUrl property for this control dynamically. To do this, write the code given below. As I have passed company name in query string, you can very easily access the respective company data from your table to display.

protected void 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;
}
}
As I've mentioned, because I've used a stored procedure you must create a stored procedure that returns tables. If you don't want to create it, just copy and paste the stored procedure given below and compile it. Make sure that your database contains all tables and respective columns.

Create Procedure [dbo].[getCompNews]

as
begin
create table #Temp
(
compname varchar(50),
news varchar(150)
)

Insert into #Temp
select a.compname, b.news from Company as a

inner join CompNews as b on a.CompId=b.CompId order by compname


Select distinct compname from #Temp
select * from #Temp
end
drop table #Temp

or

public void bind()
{
string str = " server=localhost;Data Source=xxx;" +
"uid=;pwd=;";
SqlConnection con = new SqlConnection(str);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command String, con);
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}


regards
ARUN



Post Reply
You must Sign In to post a response.
Next : Exporting to Excel
Previous : Grid View Sorting
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use