I have a form with a search text box and a grid that displays the
results. Within the grid, I have edit command links set up to
response.redirect to another page that puts the DataKey value in the
query string.
The problem is, when I return to my initial page and do another search
by entering a value in the text box then hitting enter, it takes that
value and sends it to the other page as if I hit the edit link within
the grid. Help appreciated.
<code>
<%@ Page Language="C#" Debug="True" EnableViewState="True" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="Microsoft.Data.Odbc" %>
<script runat="server">
//The Odbc above is case sensitive and everywhere in code!!! Not
only that,
// but you need to put the Microsoft.data.odbc.Dll in a Bin folder
//in your appliation directory!!!
private void Button1_Click(object sender, EventArgs ex){
//Connection Setup
OdbcConnection myConn = new
OdbcConnection("dsn=SOTAMAS90AUTO");
String strSQL = "SELECT Division + CustomerNumber As
KeyField, Division, CustomerNumber, CustomerName, ContactCode, City,
State, ZipCode, PhoneNumber FROM AR1_CustomerMaster";
//DataAdapter Setup
OdbcDataAdapter adapter = new OdbcDataAdapter(strSQL,
myConn);
//DataSet, DataAdapter & Table
DataSet objDataSet = new DataSet();
adapter.Fill(objDataSet, "dtAR1");
//Set up a filter to use the text box value...
string Filter = "CustomerName LIKE '" + TextBox1.Text +
"*'";
objDataSet.Tables[0].DefaultView.RowFilter = Filter;
objDataSet.Tables["dtAR1"].DefaultView.RowFilter = Filter;
dgAR1.DataSource = objDataSet.Tables["dtAR1"];
dgAR1.DataBind();
}
private void Button2_Click(object sender, EventArgs e) {
//Connection Setup
OdbcConnection myConn2 = new
OdbcConnection("dsn=SOTAMAS90AUTO");
String strSQL = "SELECT Division + CustomerNumber As
KeyField, Division, CustomerNumber, CustomerName, ContactCode, City,
State, ZipCode, PhoneNumber FROM AR1_CustomerMaster";
//DataAdapter Setup
OdbcDataAdapter adapter = new OdbcDataAdapter(strSQL,
myConn2);
//DataSet, DataAdapter & Table
DataSet objDataSet = new DataSet();
adapter.Fill(objDataSet, "dt2AR1");
dgAR1.DataSource = objDataSet.Tables["dt2AR1"];
dgAR1.DataBind();
}
private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) {
Response.Redirect("CRMhistory.aspx?CustomerNumber= " + (source
as DataGrid).DataKeys[e.Item.ItemIndex],false);
}
</script>
<html>
<head>
</head>
<body>
<p>
</p>
<p>
</p>
<p>
</p>
<form runat="SERVER">
<p>
</p>
<p>
<asp:Label id="Label1" runat="server"
forecolor="DarkCyan" width="137px">Customer
name like:</asp:Label>
<asp:TextBox id="TextBox1" tabIndex="1" runat="server"
EnableViewState="True" OnTextChanged="Button1_Click"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Click"
tabIndex="2" runat="server" Text="Search"></asp:Button>
<asp:Button id="Button2" onclick="Button2_Click"
tabIndex="3" runat="server" Text="Show All"></asp:Button>
</p>
<p>
<asp:DataGrid id="dgAR1" runat="server" CellPadding="3"
BorderStyle="None" DataKeyField="CustomerNumber"
OnEditCommand="DataGrid1_EditCommand" AutoGenerateColumns="False">
<HeaderStyle forecolor="White"
backcolor="DarkCyan"></HeaderStyle>
<AlternatingItemStyle
backcolor="Beige"></AlternatingItemStyle>
<Columns>
<asp:BoundColumn DataField="KeyField"
HeaderText="Key"></asp:BoundColumn>
<asp:BoundColumn DataField="Division"
HeaderText="Div"></asp:BoundColumn>
<asp:BoundColumn DataField="CustomerNumber"
HeaderText="Cust No."></asp:BoundColumn>
<asp:BoundColumn DataField="CustomerName"
HeaderText="Customer"></asp:BoundColumn>
<asp:BoundColumn DataField="ContactCode"
HeaderText="Contact"></asp:BoundColumn>
<asp:BoundColumn DataField="City"
HeaderText="City"></asp:BoundColumn>
<asp:BoundColumn DataField="State"
HeaderText="State"></asp:BoundColumn>
<asp:BoundColumn DataField="ZipCode"
HeaderText="Zip"></asp:BoundColumn>
<asp:BoundColumn DataField="PhoneNumber"
HeaderText="Phone"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="" CancelText="" EditText="HISTORY"></asp:EditCommandColumn>
</Columns>
</asp:DataGrid>
</p>
</form>
</body>
</html>
</code>
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!