473,399 Members | 3,656 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,399 software developers and data experts.

DataGrid ItemCommand not fired

I am trying to accept two input strings and concatinate and display the result in a datagrid. Following is the HTML and code. ItemCommand does not get fired what is that I am missing?

<body bgColor="#99ccff" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 288px; POSITION: absolute; TOP: 80px"
runat="server" BackColor="Silver" ForeColor="Blue" Font-Size="Small" Font-Names="Courier New"
HorizontalAlign="Center" AutoGenerateColumns="False" BorderColor="Blue" Visible="True" EnableViewState =True >
<EditItemStyle Font-Size="Small" Font-Names="Times New Roman" ForeColor="Red" BackColor="Silver"></EditItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="String1">
<ItemTemplate>
<asp:TextBox id="TextBox1" runat="server" AutoPostBack="True" Visible="True" Text= '<%# DataBinder.Eval(Container.DataItem,"val1")%>' EnableViewState = True >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="String2">
<ItemTemplate>
<asp:TextBox id=TextBox2 runat="server" AutoPostBack="True" Text= '<%# DataBinder.Eval(Container.DataItem,"val2")%>' Visible = True EnableViewState = True >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Concat Buttons">
<ItemTemplate>

<asp:LinkButton ID="Button1" Runat="server" Text="Concatinate" CommandName="Concat" EnableViewState =True > </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Result">
<ItemTemplate>
<asp:Label id="Label1" Visible="True" ForeColor="#C000C0" BackColor="#FFFFC0" Runat="server" EnableViewState =True></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>

namespace DataGridApp1
{
/// <summary>
/// Summary description for ReCalculateColumn.
/// </summary>
public class ReCalculateColumn : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
DataTable StringConcat;
DataView dv1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack)
{

BindGrid();


}

StringConcat = new DataTable();

StringConcat.Columns.Add( new DataColumn("val1", typeof(string)));
StringConcat.Columns.Add( new DataColumn("val2", typeof(string)));





}

public void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.Add( new DataColumn("val1", typeof(string)));
dt.Columns.Add( new DataColumn("val2", typeof(string)));

DataRow dr1 = dt.NewRow();
dr1[0] = "1";
dr1[1] = "2";
dt.Rows.Add(dr1);
DataRow dr2 = dt.NewRow();
dr2[0] = "3";
dr2[1] = "4";
dt.Rows.Add(dr2);

DataView dv = new DataView(dt);
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}



private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Response.Write(String.Concat("<b>ItemDataBound</b>: The = ", e.Item.ItemType.ToString(), "<br />"));

if(e.Item.ItemType == ListItemType.Item)
{
//e.Item represents a DataRow
//Cells Gets a collection of TableCell objects that represent the cells of a row in a Table control.
//The Controls property allows you programmatic access to the instance of the ControlCollection class for any server control. You can add controls to the collection, remove controls from the collection, or iterate through the server controls in the collection.
string str1 = e.Item.Cells[0].Text;
}
}

private void DataGrid1_ItemCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Response.Write(String.Concat("<b>ItemCommand</b>: The CommandName = ", e.CommandName, "<br />"));

if(e.CommandName == "Concat")
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
Label l=(Label)e.Item.Cells[3].Controls[1];
string str1 = ((TextBox)e.Item.Cells[0].Controls[1]).Text;
string str2 = ((TextBox)e.Item.Cells[1].Controls[1]).Text;
string str3 = str1 + str2;
l.Text = str3;

}
}
}

}
}
Sep 13 '07 #1
0 1015

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
1
by: Northern | last post by:
What I want to do is to retrive the value from the row that was selected by uesr. I added the "Select" command column and linked the select event to one of my method by setting my DataGrid's...
1
by: Mike | last post by:
I have a DataGrid that I am binding to a DataSet. I am adding a button to the DataGrid for users to retrieve additional information about that record. The problem I have is that the ItemCommand...
3
by: John | last post by:
The ItemCommand event not getting fired when I add both a BoundColumn and a ButtonColumn to a datagrid. When I add a ButtonColumn by itself, everything works fine, but as soon as I add a...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
2
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file...
2
by: Sekhar | last post by:
Hi all I have a DataGrid which has two Template Columns both having Image Buttons in it One column has UP image and the other has DOWN image used to reorder rows in the grid. How do i handle...
2
by: glenn | last post by:
Hi folks, Apparently, when you have a child control inside of a DataGrid, the event handler for the control does not work. I want to put a child control (checkbox, dropdownlist, etc.) into my...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.