Click here to Skip to main content
15,881,674 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I having a grid view.
ASP.NET
<asp:GridView ID="grdPurchaseBill" runat="server" CssClass="grdcls grdstyle" ShowHeader="true" AutoGenerateColumns="false" ShowFooter="true" AllowSorting="true" ShowHeaderWhenEmpty="true" EmptyDataText="No Records Found">
<Columns>
 <asp:CommandField ShowDeleteButton="True" ButtonType="Link" DeleteImageUrl="~/Images/trash.png" FooterStyle-BorderStyle="None" ItemStyle-BorderStyle="None" HeaderText="Action"> </asp:CommandField>
</asp:CommandField>
<asp:BoundField DataField="AcctId" HeaderText="Accout ID" />
<asp:BoundField DataField="CreditToAccount" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:BoundField DataField="Vat" HeaderText="VAT%" />
<asp:BoundField DataField="BasicAmount" HeaderText="Basic Amt." />
</Columns>
</asp:GridView>


and cs code is:

protected void grdPurchaseBill_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int index = Convert.ToInt32(e.CommandName.ToString());
                string accidno = grdPurchaseBill.Rows[index].Cells[2].Text.ToString();
                txtCreditToAcc.Text = accidno;
                txtamount.Text = grdPurchaseBill.Rows[index].Cells[3].Text.ToString();
                txtVat.Text = grdPurchaseBill.Rows[index].Cells[4].Text.ToString();
                txtBasicAmount.Text = grdPurchaseBill.Rows[index].Cells[5].Text.ToString();
            }
            catch (Exception ex)
            {
            }
        }


when i click on grid row the row command has fire and i seen the values are assign to textbox(using break point). but when i seen on page the textbox are empty. i tired from this. plz help
Thanks
Posted

so you need to pass another one boolean parameter to your function is registrar for event validation

C#
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(grdjournalvoucher, "$" + e.Row.RowIndex, false);
 
Share this answer
 
Comments
ABCPQR001 5-Mar-14 6:05am    
Thanks its work perfect..
I think you should use

Convert.ToInt32(e.CommandArgument) instead of CommandName to fetch the Row index value. Try it and revert with the specific errors if any.
 
Share this answer
 
Comments
ABCPQR001 26-Feb-14 7:27am    
Thanks for replay
when i replace e.CommandArgument getting error: Input string was not in a correct format.

e.CommandArgument showing blank
JoCodes 3-Mar-14 10:56am    
Add DataKeyNames="IdField" for gridview ,and CommandArgument='<%# Container.DataItemIndex %>' in the html markup for commandfield .
Mahesh_Bhosale 5-Mar-14 5:54am    
can you show me your row data bound code ?
ABCPQR001 5-Mar-14 5:58am    
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(grdjournalvoucher, e.Row.RowIndex.ToString() + "$");

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