Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
create table BoardMaster(
	BoardID int identity(1,1),
	BoardName varchar(50),
	CreateDate varchar(50),
	status bit,
	CreatedBy int
)

C# Code:
C#
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "editBoard")
       {
           int index = Convert.ToInt32(e.CommandArgument); 
    // Error - System.FormateException: Input string was not in a correct format.

           GridViewRow row = GridView1.Rows[index];

           txtBid.Text = row.Cells[1].Text;
           txtBname.Text = row.Cells[2].Text;
           txtCreatedate.Text = row.Cells[3].Text;
           int st = 1;
           if (row.Cells[4].Text == st.ToString())
           {
               cbStatus.Checked = true;
           }
           else
               cbStatus.Checked = false;

           txtCreateBy.Text = row.Cells[5].Text;
       }
   }

Asp Code:
XML
asp:GridView ID="GridView1" ShowFooter="True" AutoGenerateColumns="False"
runat="server" onrowcommand="GridView1_RowCommand1" >
<Columns>
    <asp:BoundField  DataField="BoardID" HeaderText="BoardID"
        ReadOnly="True" SortExpression="BoardID" />
    <asp:BoundField  DataField="BoardName" HeaderText="Board Name" SortExpression="BoardName" />
    <asp:BoundField  DataField="CreateDate" HeaderText="Created Date"
        SortExpression="CreateDate" />
        <asp:CheckBoxField DataField="status" HeaderText="Status" SortExpression="status"/>
        <asp:BoundField  DataField="CreatedBy" HeaderText="Created By"
        SortExpression="CreatedBy" />
    <asp:TemplateField HeaderText="Eidt">
    <ItemTemplate>
        <asp:Button ID="editBoard" CommandName="editBoard" runat="server" Text="Edit"></asp:Button>
    </ItemTemplate>
</asp:TemplateField>
</Columns>

</asp:GridView>
Posted
Updated 5-Sep-12 6:19am
v2
Comments
sahabiswarup 5-Sep-12 12:28pm    
can you please share your database design with some data..because there is no problem in your code.

1 solution

Hi,

Try this....

C#
//GridViewRow row = GridView1.Rows[index];
GridViewRow row = (GridViewRow)GridView1.NamingContainer;


Please vote if could help...

Regards,
 
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