Click here to Skip to main content
15,887,836 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionNew Features in 3.5 [modified] Pin
Kuricheti20-Feb-08 23:42
Kuricheti20-Feb-08 23:42 
GeneralRe: New Features in 3.5 Pin
Not Active21-Feb-08 2:18
mentorNot Active21-Feb-08 2:18 
GeneralRe: New Features in 3.5 Pin
Kuricheti21-Feb-08 4:51
Kuricheti21-Feb-08 4:51 
GeneralRe: New Features in 3.5 Pin
Not Active21-Feb-08 5:13
mentorNot Active21-Feb-08 5:13 
QuestionDataGrid Property Builder ??? Pin
John Sundar20-Feb-08 23:28
John Sundar20-Feb-08 23:28 
Questionleft trim Pin
Sonia Gupta20-Feb-08 23:18
Sonia Gupta20-Feb-08 23:18 
GeneralConfiguration error Pin
Member 387988120-Feb-08 22:55
Member 387988120-Feb-08 22:55 
GeneralThread: GridView isn't showing up Pin
Albert8320-Feb-08 21:43
Albert8320-Feb-08 21:43 
I am trying to bind a grid in when the user click on a button. What should happen in the button is this:
I have to txt boxes - last name, first name.
When the user clicks on the button, it should look up the last name entered in the txt box, retrieve the records if there are, and bind to the grid view. However, the results are not showing in grid at all. I created a test label which does show the values entered in the boxes. Here is the code. Thanks for reading and help.

cs code:

protected void btnFind_Click(object sender, EventArgs e)
{
string firstName = (string)txtFirstName.Text;
string lastName = (string)txtLastName.Text;

using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM users_info WHERE last_name = @last_name", conn);
cmd.Parameters.Add(new SqlParameter("@last_name", lNAme));
SqlDataReader dr = cmd.ExecuteReader();

int rowsRetrieved = 0;

while (dr.Read())
{
Label1.Text = "The value is " + dr["last_name"] + dr["first_name"];

rowsRetrieved++;
}
if (rowsRetrieved >= 1)
{
GridView1.DataSource = dr;
GridView1.DataBind();
GridView1.Visible = true;
}

Console.WriteLine("{0} row(s) retrieved", rowsRetrieved);
dr.Close();
conn.Close();
}

aspx file:

<asp:Button ID="btnFind" runat="server" Text="find" OnClick="btnFind_Click" /></td>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="first_name" HeaderText="First Name" SortExpression="first_name" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="last_name" HeaderText="Last Name" SortExpression="last_name" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>

</asp:GridView>
Generalhtml table sort and scroll with fixed header Pin
venky45620-Feb-08 21:01
venky45620-Feb-08 21:01 
GeneralRe: html table sort and scroll with fixed header Pin
Christian Graus20-Feb-08 21:09
protectorChristian Graus20-Feb-08 21:09 
QuestionSQL Pin
senthilsstil20-Feb-08 21:00
senthilsstil20-Feb-08 21:00 
GeneralRe: SQL Pin
Christian Graus20-Feb-08 21:06
protectorChristian Graus20-Feb-08 21:06 
GeneralVallidation Expression for string values Pin
SreejithAchutan20-Feb-08 20:51
SreejithAchutan20-Feb-08 20:51 
GeneralRe: Vallidation Expression for string values Pin
Christian Graus20-Feb-08 22:17
protectorChristian Graus20-Feb-08 22:17 
GeneralRe: Vallidation Expression for string values Pin
Usharva21-Feb-08 1:17
Usharva21-Feb-08 1:17 
GeneralRe: Vallidation Expression for string values Pin
SreejithAchutan21-Feb-08 16:15
SreejithAchutan21-Feb-08 16:15 
QuestionChanges is not applying [modified] Pin
~V~20-Feb-08 20:24
~V~20-Feb-08 20:24 
GeneralRe: Changes is not applying Pin
Christian Graus20-Feb-08 20:38
protectorChristian Graus20-Feb-08 20:38 
GeneralRe: Changes is not applying Pin
~V~20-Feb-08 20:40
~V~20-Feb-08 20:40 
GeneralRe: Changes is not applying Pin
~V~21-Feb-08 19:20
~V~21-Feb-08 19:20 
GeneralReading an HTML file and putting to database. Pin
Trav120-Feb-08 20:23
Trav120-Feb-08 20:23 
GeneralRe: Reading an HTML file and putting to database. Pin
Christian Graus20-Feb-08 20:42
protectorChristian Graus20-Feb-08 20:42 
QuestionHow to Create Microsite Pin
raushan_920-Feb-08 19:46
raushan_920-Feb-08 19:46 
AnswerRe: How to Create Microsite Pin
Christian Graus20-Feb-08 20:52
protectorChristian Graus20-Feb-08 20:52 
QuestionHow to draw a transparent rectangle on an image in asp.net 2.0-ITS URGENT! Pin
Adwita20-Feb-08 19:06
Adwita20-Feb-08 19:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.