473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Edit Command Problem


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>
&nbsp;<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>
&nbsp;
<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!
Nov 16 '05 #1
0 1559

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
0
by: San Diego Guy | last post by:
Hi all! I have Datagrid. Within that datagrid I have a drop down list that I set up some values in (a "collection") I set up an edit command column on the datagrid and wrote simple code to get...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
3
by: misiek | last post by:
Hi all. I have following problem: 1. In my web page I have a GridView control, which does not have a DataSourceId set in designer. 2. When user presses Start button then I create...
0
by: Kaushik Gadani | last post by:
I am using VB as code behind of ASP.Net (Framework 1.1) I want to call grid's edit command through javascript. This requirements comes, when I want to facilitate user to call edit command by...
0
by: den 2005 | last post by:
Hi everybody, I am not familiar using Gridview, I created a Gridview with Edit Command Button, but when I click the update Command button this error message below is displayed, what and where is...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: jmacduff | last post by:
Big question: How to enable edit/update commands to work when setting the sqldatasource select command from code behind. Details: I have a GridView using a sqldatasouce with the select and...
1
by: ollielaroo | last post by:
Hi guys, Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site. My problem is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.