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

Buttons in Datagrids

Anyone know if it is possible to have a button inside a datagird that will
launch a new window? I have a button on my webform that does this currently
and it works fine. I took that code and put a button into the datagrid
template and wanted it to do the same thing per line and pass that line
information into the window it launches, however, it is not working. so far
the only code I have on the button is below and it doesn't work.

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

{

string sUrl = "ChangeForm.aspx";

string sFeatures = "'height=320;width=160;left=100;top=50;'";

string sScript;

sScript = "<script language=javascript>" +

"window.open('" + sUrl + "',''," + sFeatures + ");"+

"</script>";

// Write it into the output stream for immediate execution

Response.Write(sScript);

}
Nov 16 '05 #1
1 1155
Hi Brian
look at this example
<asp:datagrid DataKeyField="DiscId" id="DataGrid1" style="Z-INDEX: 110;
LEFT: 8px; POSITION: absolute; TOP: 408px"
runat="server" AutoGenerateColumns="False" CellPadding="8"
BorderWidth="2px" BorderColor="Yellow">
<HeaderStyle ForeColor="White" BackColor="Indigo"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="DiscId" HeaderText="ID">
<ItemStyle HorizontalAlign="Center" ForeColor="White"
BackColor="Purple"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="FloatDiscNumber" SortExpression="DES"
HeaderText="FloatNumber">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="PackDescription" HeaderText="Catagory">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipmentName" HeaderText="Issue Date">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="LabelText" HeaderText="DVD Content">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Color" HeaderText="Color">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="DiscImageFile" HeaderText="Image">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:ButtonColumn Text="Book" ButtonType="PushButton"
HeaderText="Reserve" CommandName="reserve">
<ItemStyle BackColor="Purple"></ItemStyle>
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="DVD View">
<ItemStyle BackColor="Purple"></ItemStyle>
<ItemTemplate>
<asp:Button runat="server" Text="Details" CommandName="opencontent"
CausesValidation="false"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Then you can code the events as so
private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName.Equals("reserve"))
{
//code to handle event of that button
}
else
{
// code to handle the other
}
}

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

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

Similar topics

5
by: Phil Townsend | last post by:
I need to add a button to a datagrid. I have tried using the ButtonColumn and have also tried adding a button to a templatecolumn > itemtemplate. Whatever I have tried doesn't work, nor does it...
1
by: Darren D'Orlando | last post by:
I recently had a problem with my computer, the keyboard stopped working. I fixed that then I couldn't connect to the my IIS server, it no longer recognized my computer as a server...So I...
1
by: Simon Harris | last post by:
Hi All, I wish to populate more than one datagrid from the same OleDBCommand. The code I have is: Dim objCmd As New OleDbCommand(strSql, objConn) Then... ...
4
by: ree32 | last post by:
I have a placeholder and depending on a user input(a drop downlist) when the user clicks a button I dynamically create a number of datagrids and fill them with data from a database. But the problem...
0
by: Scott Meddows | last post by:
I'm having trouble scrolling some datagrids so they sync up... I have two identical datagrids on a form, filled with eh same dataset. I want a user to be able to scroll on the datasets and the...
3
by: Li Pang | last post by:
Hi, I want to know how to add radio buttons into a datagrid control. Thanks
0
by: tshad | last post by:
Does anyone know if MS has fixed the problem with radio buttons with respect to Datagrids Asp.Net 2.0? I have to use a 3rd party Radio button to use it with Datagrids, since they will not keep...
7
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
0
by: tshad | last post by:
I remember Radio buttons having problem keeping values in datagrids in VS 2003. To solve the problem I had picked up a use control from Metabuilders (RowSelectorColumn). This worked real well...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.