KavyaVS
asked on
GridView RowCommand is not firing
Hi,
This is the GridView markup and Grid_RowCommand is not firing.
When LinkButton is clicked it has to fire the Grid_RowCommand. But it is not.
Please look into the markup and code and let me know your suggestions.
<asp:GridView ID="grd1" runat="server" SkinID="GridView10RowsSort AndPage" OnRowCommand="Grid_RowComm and"
OnRowDataBound="Grid_RowDa taBound">
<Columns>
<asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:LinkButton ID="btnAmt" runat="server" Text='<%# Bind("AMOUNT")%>'
CommandName="Select"></asp :LinkButto n>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Bind("DESCRIPTION")%>'></a sp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbldate" runat="server" Text='<%# Bind("Date")%>'></asp:Labe l>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Time">
<ItemTemplate>
<asp:Label ID="lbltime" runat="server" Text='<%# Bind("TIME")%>'></asp:Labe l>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Bind("Name")%>'></asp:Labe l>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView grd = (GridView)sender;
try
{
int iRowIndex = Convert.ToInt32(e.CommandA rgument);
switch (grd.ID.ToString())
{
case "grd1":
{
LinkButton lnk = (LinkButton)grd1.Rows[iRow Index].Cel ls[1].Cont rols[0];
ViewState["SelectedRow"] = grd1.Rows[iRowIndex].Cells [0].Text.T rim();
txtDate.Text = grd1.Rows[iRowIndex].Cells [3].Text.T rim();
txtAmount.Text = lnk.Text.Trim();
txtType.Text = grdTrans.Rows[iRowIndex].C ells[2].Te xt.Trim();
break;
}
}
}
catch (Exception ex)
{
string s = ex.Message;
}
finally
{
}
}
Do I need to change anything please.
Thanks
This is the GridView markup and Grid_RowCommand is not firing.
When LinkButton is clicked it has to fire the Grid_RowCommand. But it is not.
Please look into the markup and code and let me know your suggestions.
<asp:GridView ID="grd1" runat="server" SkinID="GridView10RowsSort
OnRowDataBound="Grid_RowDa
<Columns>
<asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:LinkButton ID="btnAmt" runat="server" Text='<%# Bind("AMOUNT")%>'
CommandName="Select"></asp
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Bind("DESCRIPTION")%>'></a
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbldate" runat="server" Text='<%# Bind("Date")%>'></asp:Labe
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Time">
<ItemTemplate>
<asp:Label ID="lbltime" runat="server" Text='<%# Bind("TIME")%>'></asp:Labe
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Bind("Name")%>'></asp:Labe
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView grd = (GridView)sender;
try
{
int iRowIndex = Convert.ToInt32(e.CommandA
switch (grd.ID.ToString())
{
case "grd1":
{
LinkButton lnk = (LinkButton)grd1.Rows[iRow
ViewState["SelectedRow"] = grd1.Rows[iRowIndex].Cells
txtDate.Text = grd1.Rows[iRowIndex].Cells
txtAmount.Text = lnk.Text.Trim();
txtType.Text = grdTrans.Rows[iRowIndex].C
break;
}
}
}
catch (Exception ex)
{
string s = ex.Message;
}
finally
{
}
}
Do I need to change anything please.
Thanks
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks
ASKER
<asp:GridView ID="grd1" runat="server" SkinID="GridView10RowsSort
OnRowDataBound="Grid_RowDa
protected void Grid_ItemDataBound(object sender, System.Web.UI.WebControls.
{
GridView grd = (GridView)sender;
try
{
switch (grd.ID.ToString())
{
case "grd1":
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingIt
{
LinkButton lnkAmt= e.Item.FindControl("btnAmt
lnkAmt.Attributes.Add("onc
}
break;
}
}
}
catch (Exception ex)
{
string s = ex.Message;
}
finally
{
}
}
Any suggestions please.
Thanks.