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.redire ct 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="Syst em.Data" %>
<%@ import Namespace="Micr osoft.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(o bject sender, EventArgs ex){
//Connection Setup
OdbcConnection myConn = new
OdbcConnection( "dsn=SOTAMAS90A UTO");
String strSQL = "SELECT Division + CustomerNumber As
KeyField, Division, CustomerNumber, CustomerName, ContactCode, City,
State, ZipCode, PhoneNumber FROM AR1_CustomerMas ter";
//DataAdapter Setup
OdbcDataAdapter adapter = new OdbcDataAdapter (strSQL,
myConn);
//DataSet, DataAdapter & Table
DataSet objDataSet = new DataSet();
adapter.Fill(ob jDataSet, "dtAR1");
//Set up a filter to use the text box value...
string Filter = "CustomerNa me LIKE '" + TextBox1.Text +
"*'";
objDataSet.Tabl es[0].DefaultView.Ro wFilter = Filter;
objDataSet.Tabl es["dtAR1"].DefaultView.Ro wFilter = Filter;
dgAR1.DataSourc e = objDataSet.Tabl es["dtAR1"];
dgAR1.DataBind( );
}
private void Button2_Click(o bject sender, EventArgs e) {
//Connection Setup
OdbcConnection myConn2 = new
OdbcConnection( "dsn=SOTAMAS90A UTO");
String strSQL = "SELECT Division + CustomerNumber As
KeyField, Division, CustomerNumber, CustomerName, ContactCode, City,
State, ZipCode, PhoneNumber FROM AR1_CustomerMas ter";
//DataAdapter Setup
OdbcDataAdapter adapter = new OdbcDataAdapter (strSQL,
myConn2);
//DataSet, DataAdapter & Table
DataSet objDataSet = new DataSet();
adapter.Fill(ob jDataSet, "dt2AR1");
dgAR1.DataSourc e = objDataSet.Tabl es["dt2AR1"];
dgAR1.DataBind( );
}
private void DataGrid1_EditC ommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e) {
Response.Redire ct("CRMhistory. aspx?CustomerNu mber=" + (source
as DataGrid).DataK eys[e.Item.ItemInde x],false);
}
</script>
<html>
<head>
</head>
<body>
<p>
</p>
<p>
</p>
<p>
</p>
<form runat="SERVER">
<p>
</p>
<p>
<asp:Labe l id="Label1" runat="server"
forecolor="Dark Cyan" width="137px">C ustomer
name like:</asp:Label>
<asp:TextBox id="TextBox1" tabIndex="1" runat="server"
EnableViewState ="True" OnTextChanged=" Button1_Click"> </asp:TextBox>
<asp:Button id="Button1" onclick="Button 1_Click"
tabIndex="2" runat="server" Text="Search"></asp:Button>
<asp:Button id="Button2" onclick="Button 2_Click"
tabIndex="3" runat="server" Text="Show All"></asp:Button>
</p>
<p>
<asp:DataGrid id="dgAR1" runat="server" CellPadding="3"
BorderStyle="No ne" DataKeyField="C ustomerNumber"
OnEditCommand=" DataGrid1_EditC ommand" AutoGenerateCol umns="False">
<HeaderStyle forecolor="Whit e"
backcolor="Dark Cyan"></HeaderStyle>
<AlternatingIte mStyle
backcolor="Beig e"></AlternatingItem Style>
<Columns>
<asp:BoundColum n DataField="KeyF ield"
HeaderText="Key "></asp:BoundColumn >
<asp:BoundColum n DataField="Divi sion"
HeaderText="Div "></asp:BoundColumn >
<asp:BoundColum n DataField="Cust omerNumber"
HeaderText="Cus t No."></asp:BoundColumn >
<asp:BoundColum n DataField="Cust omerName"
HeaderText="Cus tomer"></asp:BoundColumn >
<asp:BoundColum n DataField="Cont actCode"
HeaderText="Con tact"></asp:BoundColumn >
<asp:BoundColum n DataField="City "
HeaderText="Cit y"></asp:BoundColumn >
<asp:BoundColum n DataField="Stat e"
HeaderText="Sta te"></asp:BoundColumn >
<asp:BoundColum n DataField="ZipC ode"
HeaderText="Zip "></asp:BoundColumn >
<asp:BoundColum n DataField="Phon eNumber"
HeaderText="Pho ne"></asp:BoundColumn >
<asp:EditComman dColumn ButtonType="Lin kButton"
UpdateText="" CancelText="" EditText="HISTO RY"></asp:EditCommand Column>
</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!