I am using SQL command to insert and delete into the grid but getting following errors while executing.
Error 1 Use of unassigned local variable 'cmd' (This is at INSERT INTO Table(ID,Summary) values ('" + Convert)
Error 2 'System.DateTime' does not contain a definition for 'Text'
Error 3 'System.EventArgs' does not contain a definition for 'CommandName' and no extension method 'CommandName' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)
Error 4 'System.EventArgs' does not contain a definition for 'CommandArgument' and no extension method 'CommandArgument' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?)
Error 5 The name 'fillgrid' does not exist in the current context
The HTML part is correct . But I think I have not written the insert and delete function properly
This is the HTML code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title> </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="label" runat="server">New Task</asp:Label>
<asp:TextBox ID="textbox1" runat="server" placeHolder="Type
new task summary here, and click add" Width="353px">
</asp:TextBox>
<asp:Button ID="button1" runat="server" OnClick="click_add"
Text="Add" style="margin-left: 54px" Width="67px" />
<br />
</div>
<asp:GridView ID="grdStatus" runat="server"
OnRowCommand="grdStatus_RowCommand" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Done?">
<ItemTemplate>
<asp:CheckBox ID="checkbx" runat="server"
Checked='<%#Eval("Done") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="label12" runat="server"
Checked='<%#Container.DataItemIndex+1 %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Summary">
<ItemTemplate>
<asp:Label ID="label3" runat="server"
Checked='<%#Eval("Summary") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created On">
<ItemTemplate>
<asp:Label ID="label4" runat="server"
Checked='<%#Eval("Date")%>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="dltButton" runat="server"
ImageUrl="~/images/delete.png"
CommandName="DeleteTask" Text="Delete" Width="30px"
Height="30px" CommandArgument="<%#
Container.DataItemIndex%>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
The c# code is this
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string connectionString =
WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
string selectSQL = "SELECT * FROM Table";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "Table");
grdStatus.DataSource = ds;
grdStatus.DataBind();
}
}
protected void click_add(object sender, EventArgs e)
{
string connectionString =
WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO
Table(ID,Summary) values ('" +
convert.ToInt32(cmd.Parameters["label2"].Value.ToString())
+ "'" + textbox1.Text + "'" DateTime.Text+ "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
protected void grdStatus_RowCommand(object sender, EventArgs e)
{
if(e.CommandName == "DeleteTask")
{
string connectionString =
WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string query = "delete from Table where id=" +
e.CommandArgument + "'";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
fillgrid();
}
}
}
Related
My C# Code
public partial class Message : System.Web.UI.Page
{
String strconn = ConfigurationManager.ConnectionStrings["db"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
members();
}
public void members()
{
SqlConnection con = new SqlConnection(strconn);
con.Open();
try
{
string str = "Select Users.Username,Users.Name,ProfilePic.Pathh From Users FULL OUTER JOIN ProfilePic ON Users.username = ProfilePic.Username ORDER BY Users.Sno";
SqlCommand cmd = new SqlCommand(str,con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
repMembers.DataSource = ds;
repMembers.DataBind();
GridView1.DataSource = ds;
GridView1.DataBind();
cmd.Dispose();
con.Close();
}
catch(Exception ex) {
lbMembers.Text = ex.ToString();
}
}
}
And My HTML Code
<asp:Repeater ID="repMembers" runat="server" >
<asp:ItemTemplate >
<div style="width:100%; border-bottom:#ffffff 2px solid;"> <asp:Image ID="Image4" runat="server" ImageUrl='<%#Eval("Pathh") %>' width="60px" Height="60px"/> <asp:Label ID="lb" runat="server" Text='<%#Eval("Username") %>'></asp:Label><br/><asp:Label ID="lbname" runat="server" Text='<%#Eval("Name") %>'></asp:Label><br/></div>
</asp:ItemTemplate>
</asp:Repeater>
My Table is absolutely correct and is working, i checked it with Grid View. It gives me the "Name","Username", and "Path" Stored.
I checked it with SQL query and displayed it in grid view.
This is the Photo of my table,it is the combination of two tables
Use ItemTemplate instead of asp:ItemTemplate. There's also a typo with the word "Pathh", does this solve your issue?
<ItemTemplate >
<div style="width:100%; border-bottom:#ffffff 2px solid;">
<asp:Image ID="Image4" runat="server" ImageUrl='<%#Eval("Path") %>' width="60px" Height="60px"/>
<asp:Label ID="lb" runat="server" Text='<%#Eval("Username") %>'></asp:Label>
<br/>
<asp:Label ID="lbname" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
<br/>
</div>
</ItemTemplate>
I have an issue trying to display image in my DataList from the database and have access to the database that I'm pulling my images from. But when I run the WebForm the image does not appear, what is wrong in my codes?
<asp:DataList ID="DataList1" runat="server" DataKeyField="dishID" DataSourceID="SqlDataSource1" BorderStyle="Solid" GridLines="Both" RepeatColumns="4" RepeatDirection="Horizontal" Width="1259px" >
<ItemTemplate>
<table class="auto-style1">
<tr><td>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "FoodPictures/" + Eval("dishImage") %>' />
This is how I'm retrieving from the database:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(_connStr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Dish";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
conn.Close();
DataList1.DataSource = dt;
DataList1.DataBind();
conn.Close();
}
I think Your Page do not get image on proper path....
use
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "../FoodPictures/" + Eval("dishImage") %>' />
Or
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/FoodPictures/" + Eval("dishImage") %>' />
Try this..
Assuming if dishImage is a name like imagename.jpg stored in database then try Convert.ToString(Eval("dishImage")) like:
<asp:Image ID="Image1" ImageUrl='<% # "~/FoodPictures/" + Convert.ToString(Eval("dishImage")) %>' runat="server" />
I have a problem to update a datagridview when modifications are made.
To update a column ("Criticite"), I implemented a DropDownList containing 2 choices. I can select a choice, but I click on the "Update" button none change is done.
Could you please help me on this subject ?
Thanks a lot !
Here is the C# code :
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO.Compression;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindData();
}
}
private void BindData()
{
string query = "select ID,Client,Entite,Date,Source,Domaine,Categorie,SousCategorie,Criticite,Contenu from Results";
SqlCommand cmd = new SqlCommand(query);
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
private DataTable GetData(SqlCommand cmd)
{
string strConnString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
protected void EditCustomer(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void CancelEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList drpcategory1 = (DropDownList)e.Row.FindControl("DropDownList1");
String query = "Select Criticite from Results";
SqlCommand cmd = new SqlCommand(query);
DataTable dt = GetData(cmd);
drpcategory1.DataSource = dt;
drpcategory1.DataTextField = "Criticite";
drpcategory1.DataValueField = "Criticite";
drpcategory1.DataBind();
}
}
private void BindData(string Query)
{
string connectionstring = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionstring))
{
conn.Open();
using (SqlCommand comm = new SqlCommand(Query + ";select ID,Client,Entite,Date,Source,Domaine,Categorie,SousCategorie,Criticite,Contenu from Results", conn))
{
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
protected void RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label ID = GridView1.Rows[e.RowIndex].FindControl("ID") as Label;
TextBox Entite = GridView1.Rows[e.RowIndex].FindControl("txtEntite") as TextBox;
TextBox Date = GridView1.Rows[e.RowIndex].FindControl("txtDate") as TextBox;
TextBox Source = GridView1.Rows[e.RowIndex].FindControl("txtSource") as TextBox;
TextBox Domaine = GridView1.Rows[e.RowIndex].FindControl("txtDomaine") as TextBox;
TextBox Categorie = GridView1.Rows[e.RowIndex].FindControl("txtCategorie") as TextBox;
TextBox SousCategorie = GridView1.Rows[e.RowIndex].FindControl("txtSousCategorie") as TextBox;
TextBox Criticite = GridView1.Rows[e.RowIndex].FindControl("lblCriticite") as TextBox;
TextBox Contenu = GridView1.Rows[e.RowIndex].FindControl("txtContenu") as TextBox;
String UpdateQuery = string.Format("UPDATE Results SET Entite='{0}',Date='{1}',Source='{2}',Domaine='{3}',Categorie='{4}',SousCategorie='{5}',Criticite='{6}',Contenu='{7}' WHERE ID = {8}", Entite.Text, Date.Text, Source.Text, Domaine.Text, Categorie.Text, SousCategorie.Text, Criticite.Text, Contenu.Text, ID.Text);
GridView1.EditIndex = -1;
BindData(UpdateQuery);
}
}
And here the aspx default page :
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<p>
Début</p>
<p>
</p>
<p>
</p>
<asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="false"
AlternatingRowStyle-BackColor="#EEEEEE" EditRowStyle-BorderColor="Red"
OnRowEditing = "EditCustomer"
OnRowDataBound = "RowDataBound"
OnRowUpdating = "RowUpdating"
OnRowCancelingEdit = "CancelEdit">
<Columns>
<asp:TemplateField Visible="false" HeaderText="ID">
<ItemTemplate>
<asp:Label runat="server" ID="ID" Text='<%#Eval("ID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Client">
<ItemTemplate>
<asp:Label runat="server" ID="Client" Text='<%#Eval("Client") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtClient" Text='<%#Eval("Client") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Entite">
<ItemTemplate>
<asp:Label runat="server" ID="Entite" Text='<%#Eval("Entite") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtEntite" Text='<%#Eval("Entite") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label runat="server" ID="Date" Text='<%#Eval("Date") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtDate" Text='<%#Eval("Date") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Source">
<ItemTemplate>
<asp:Label runat="server" ID="Source" Text='<%#Eval("Source") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtSource" Text='<%#Eval("Source") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Domaine">
<ItemTemplate>
<asp:Label runat="server" ID="Domaine" Text='<%#Eval("Domaine") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtDomaine" Text='<%#Eval("Domaine") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Categorie">
<ItemTemplate>
<asp:Label runat="server" ID="Categorie" Text='<%#Eval("Categorie") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtCategorie" Text='<%#Eval("Categorie") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SousCategorie">
<ItemTemplate>
<asp:Label runat="server" ID="SousCategorie" Text='<%#Eval("SousCategorie") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtSousCategorie" Text='<%#Eval("SousCategorie") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Criticite">
<ItemTemplate>
<asp:Label runat="server" ID="lblCriticite" Text='<%#Eval("Criticite") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="lblCriticite" Text='<%#Eval("Criticite") %>' Visible = "false" />
<asp:DropDownList ID="DropDownList1" runat = "server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contenu">
<ItemTemplate>
<asp:Label runat="server" ID="Contenu" Text='<%#Eval("Contenu") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtContenu" Text='<%#Eval("Contenu") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
Change the following line
TextBox Criticite = GridView1.Rows[e.RowIndex].FindControl("lblCriticite") as TextBox;
into:
DropDownList Criticite = GridView1.Rows[e.RowIndex].FindControl("DropDownList1") as DropDownList;
and use Criticite.SelectedValue instead of Criticite.Text.
Also, your update query is at risk of SQL injection attacks.
I'm using a Datalist to show countries list each record having a Gridview containing a list of states and each state having a Dropdownlist for cities. I am using a hidden field to get the ID of country to retrieve the name of state for every record by using Eval("C_ID") in the hidden field. But it raises ArgumentOutOfRangeException. I'm not able to know what I'm doing wrong.
Here is the code for Datalist:
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" onitemdatabound="DataList1_ItemDataBound" >
<ItemTemplate>
<table border="1px">
<tr>
<td>
<%#Eval("C_Name") %><br />
<asp:HiddenField ID="HiddenField1" Value='<%#Eval("C_ID") %>' runat="server" />
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="State Cities">
<ItemTemplate >
<asp:CheckBox ID="CheckBox1" runat="server" />
<%#Eval("S_Name") %>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
and this is code behind:
public partial class AdvancedTable : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString);
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from Country", con);
con.Open();
da.Fill(ds, "Country");
con.Close();
DataList1.DataSource = ds;
DataList1.DataBind();
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
SqlDataAdapter da2 = new SqlDataAdapter();
da2.SelectCommand = new SqlCommand("select * from State where C_ID='"+((HiddenField)DataList1.Items[e.Item.ItemIndex].FindControl("HiddenField1")).Value+"'",con);
con.Open();
da2.Fill(ds, "State");
con.Close();
((GridView)e.Item.FindControl("GridView1")).DataSource = ds.Tables["State"];
((GridView)e.Item.FindControl("GridView1")).DataBind();
}
}
Perhaps, instead of DataList1.Items[e.Item.ItemIndex].FindControl("HiddenField1")
Just use e.Item.FindControl("HiddenField1")
Instead, you can do the following:
<asp:DropDownList ID="DropDownList1" runat="server" DataSource="<%# GetList((int)Eval("C_ID"))%>">
</asp:DropDownList>
In the code Behind
protected DataTable GetList(int id){ }
Wondering where I'm going wrong here. I'm page loads but when I click on the search (after I type something in the last name field) it just clocks and clocks.
Here's my aspx.cs page:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("SERVER=ServerName;Trusted_Connection=Yes;DATABASE=DBNAME"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "customerSearchStoredProc";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#lName", lNameTextbox.Text);
cmd.Connection = con;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(ds);
}
con.Close();
}
GridView1.DataSource = ds;
GridView1.DataBind();
/*SqlDataAdapter adp = new SqlDataAdapter("customerSearchStoredProc", con);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
adp.SelectCommand.Parameters.Add(new SqlParameter("#lName", System.Data.SqlDbType.Text));
//adp.SelectCommand.Parameters.Add(new SqlParameter("#State", System.Data.SqlDbType.Text));
adp.SelectCommand.Parameters["#lName"].Value = lNameTextbox.Text;
//adp.SelectCommand.Parameters["#State"].Value = StateTextbox.Text;
adp.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();*/
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Here's my aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %> <%# OutputCache Duration="1" VaryByParam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">
<title>MSS Archive Page</title> </head> <body>
<form id="form1" runat="server">
<asp:Label ID="Label1" Text="Last Name" runat="server" />
<asp:TextBox ID="lNameTextbox" runat="server"></asp:TextBox>
<asp:Label ID="Label2" Text="First Name" runat="server" />
<asp:TextBox ID="fName" runat="server" ></asp:TextBox>
<!-- <asp:Label ID="Label3" Text="Street" runat="server" />
<asp:TextBox ID="Street" runat="server" AutoPostBack="True"></asp:TextBox><br />
<asp:Label ID="Label4" Text="City" runat="server" />
<asp:TextBox ID="City" runat="server" AutoPostBack="True" ></asp:TextBox> -->
<asp:Label ID="Label5" Text="State" runat="server" /> <!-- <asp:TextBox ID="State" runat="server" AutoPostBack="True"></asp:TextBox> -->
<asp:TextBox ID="StateTextbox" runat="server" ReadOnly="True">MA</asp:TextBox>
<asp:Label ID="Label6" Text="Zip" runat="server" />
<asp:TextBox ID="Zip" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" PostBackUrl="~/Default.aspx" Text="Search" OnClick="Button1_Click" /><br />
OR<br />
<asp:Label ID="Label7" Text="Policy" runat="server" />
<asp:TextBox ID="Policy" runat="server"></asp:TextBox>
<asp:Label ID="Label8" Text="Account" runat="server" />
<asp:TextBox ID="Account" runat="server"></asp:TextBox> <br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" OnDataBinding="Button1_Click" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
</asp:GridView>
<br />
</form> </body> </html>
Thanks for the help!
Your databinding is calling the on click.
OnDataBinding="Button1_Click"
In the on click you call databind.
GridView1.DataBind();
To me that looks like a loop going on forever.
I see that the GridView has no columns explicitly defined, and you've got AutoGenerateColumns = false.
Is that an omission from the code, or is your code really like that? If so, then the GridView won't show anything. Try setting AutoGenerateColuns = "true" and see if anything shows up. If so, then the problem is you need to explicitly define your columns.