Click here to Skip to main content
15,924,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all
I am developing movie theater seats booking website, for that i have placed images as Seats in asp:gridview(all cells) using ImageButton Template, for selection of seat click on ImageButton(cell) at that time i need that cell value where i clicked ImageButton in gridview.

I am getting RowIndex but not ColIndex.

Please help me..
Posted

Use datakey name on the gridview property
Use query string for retrieving ID
 
Share this answer
 
Comments
mahigurrala 7-Sep-11 3:12am    
How to add DataKey to each cell in gridview at runtime.
You can use on RowCommand Method
C#
int id = (int)GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value;
 
Share this answer
 
Comments
mahigurrala 6-Sep-11 1:57am    
<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False"
Width="755px" AllowPaging="True"

PageSize="26" ShowHeader="true" CellSpacing="1"
onrowupdating="Gridview1_RowUpdating"
onrowcommand="Gridview1_RowCommand">
<rowstyle borderstyle="None">

<columns>


<asp:TemplateField >
<itemtemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# Eval("SeatRow") %>' runat="server">

<itemstyle borderstyle="None">



<asp:TemplateField HeaderText ="1" >

<itemtemplate>

<asp:ImageButton ID="ImageButton1" CommandArgument='<%# Eval("C1") %>' CommandName="ib1"
Visible='<%# MyVisible(Eval("C1").ToString()) %>' runat="server" ImageUrl='<%# MyImg(Eval("C1").ToString()) %>' Text='<%# MyValue(Eval("C1").ToString()) %>' OnClick ="ImageButton1_Click"/>

<itemstyle borderstyle="None">


<asp:TemplateField HeaderText ="2">
<itemtemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CommandArgument='<%# Eval("C2") %>'
CommandName="ib2" Visible='<%# MyVisible(Eval("C2").ToString()) %>' ImageUrl='<%# MyImg(Eval("C2").ToString()) %>'
OnClick="button_click" RowIndex='<%# Container.DisplayIndex %>'/>

<itemstyle borderstyle="None">


<asp:TemplateField HeaderText ="3">
<itemtemplate>
<asp:ImageButton ID="ImageButton3" runat="server" CommandArgument='<%# Eval("C3") %>'
CommandName="ib3" Visible='<%# MyVisible(Eval("C3").ToString()) %>' ImageUrl='<%# MyImg(Eval("C3").ToString()) %>'/>

<itemstyle borderstyle="None">





<footerstyle borderstyle="None">
<SelectedRowStyle BorderStyle="None" />
<editrowstyle borderstyle="None">
<alternatingrowstyle borderstyle="None">



Defaust.aspx.cs

public bool MyVisible(string txt)
{
txtNum = txt;
if (txt == "")
{
return false;
//Gridview1
}
else { return true; }
}

string ImgPath = "";
public string MyImg(string txt)
{
try
{
if (txtNum == "1")
ImgPath = "~/Images/wchair.JPG";
else
I
uspatel 6-Sep-11 2:42am    
You can also try this method
private void GridView1_Cell_Click(object sender, GridViewCellEventArgs e)
{
int cellindex=e.CellIndex;
int rowindex =e.rowindex;
var value = GridView1.Rows[rowindex].Cells[cellindex].value;

}
On Image Button, Add a Event handler for with Command Argument as the Set Number or whatever. That you can take and pass a bind expression in gridview.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900