i have taken gridviw to display records and pageindex=true
it was working well...
but now i have added one buttonfield with commandname="SELECT"
with GridView1_RowCommand event to deal with this btnfield..
when i click on this buttonfield thats working well..
but raise error when i do paging...
Error:
Input string was not in a correct format.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index=Convert.ToInt32(e.CommandArgument);
Sailaja YPosted Mar 22, 2010, 8:31 AM
For selecting,sorting,deleting,paging.etc .We use the RowCommand event.
This event first expects the CommandName according to which the method can be decided.
See the below link for further help.
http://forums.asp.net/p/1224961/2195594.aspx#2195594
If this helped you,mark it as answer.
Regards,
Dipa AhujaPosted Mar 22, 2010, 8:45 AM
i got the reason of my error..
i have to put the first statment of gridview_rowcommand event as
if (e.commandName=="")
bt i put that two statments before that... but thanx anyways..
i marked your answer
Dipa AhujaPosted Mar 22, 2010, 7:32 AM
as i explained my error i took 1st gridview with paging
<asp:GridView PagerSettings-Position="TopAndBottom" ID="GridView1" runat="server" AllowPaging="True"
DataSourceID="photos" Width="1000px" PageSize="1" AutoGenerateColumns="False"
DataKeyNames="ImgId" OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
<PagerSettings FirstPageText="" LastPageText=""
Mode="NextPrevious" NextPageText="" Position="TopAndBottom"
PreviousPageText="" FirstPageImageUrl="~/icons/pre.jpg"
LastPageImageUrl="~/icons/next.jpg" NextPageImageUrl="~/icons/next.jpg"
PreviousPageImageUrl="~/icons/pre.jpg" />
<Columns>
<asp:TemplateField> <ItemTemplate>
<asp:ImageImageAlign="Middle"
BorderWidth="1" ID="imagdisp" runat="server"
ImageUrl='<%# Bind ("Image","albumImages/{0}")%>' BorderColor="#660033" />
<asp:Label Visible="false" runat="server" ID="imgid"
Text='<%# Bind("ImgId") %>' />
<br />ItemTemplate>asp:TemplateField>
Columns>asp:GridView>
till this paging is working well...but then i wanted to add one button field..
then i added :
<asp:ButtonField Text="Select as Album cover" CommandName="Select" ButtonType="Link" />
and the gridview_rowcommand event
.cs
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index=Convert.ToInt32(e.CommandArgument);
string url=((Image)GridView1.Rows[index].FindControl("imagdisp")).ImageUrl.ToString();
if (e.CommandName == "Select")
{
objconn.Open();
string q="Update albums set aimage=@aimage where aid=@aid";
SqlCommand comm = new SqlCommand(q, objconn);
comm.Parameters.AddWithValue("@aimage",url.ToString());
comm.Parameters.AddWithValue("aid",aid);
comm.ExecuteNonQuery();
objconn.Close();
}
GridView1.DataBind();
}
the page doesn't cause this error when i click on that button but cause error when i press any next/prev button of paging!
BangaruBabu PuretiPosted Mar 22, 2010, 5:24 AM
Hi Daya
commandname="SELECT"
select is a key word.Can U Please Select Another Command Name Like get or Some thing.
if Even Ur Not Getting The Accuracy.Please Check Ur Sql Queries and ALL
Regards
BangaruBabuPureti
Amit ChoudharyPosted Mar 22, 2010, 1:12 AM
What you want to extract from these lines??
???????