I am having one friend request form.In that,I have used grid view control to show all registered members,So one who want to send request he/she can send request.My form design code is:
<asp:GridView ID="grdviewFriendRequest" runat="server" AllowPaging="true" AutoGenerateColumns="false"
EmptyDataText="No members found" Width="100%" Font-Size="16px" ForeColor="#FF9F00"
GridLines="None" PagerSettings-Mode="NumericFirstLast"
onselectedindexchanged="grdviewFriendRequest_SelectedIndexChanged">
<FooterStyle BackColor="#FFB100" Font-Bold="true" ForeColor="#000000" />
<RowStyle BackColor="#FFD340" />
<EditRowStyle BackColor="#FFDE40" />
<SelectedRowStyle BackColor="#FFC900" Font-Bold="True" ForeColor="#000000" />
<PagerStyle BackColor="#FFEB73" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#FFB100" Font-Bold="True" ForeColor="000000" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="#FFDF73" />
<Columns>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<%#Eval("firstName")%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<%#Eval("lastName")%></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Send Friend Request">
<ItemTemplate>
<asp:Button ID="btnSendFrndReq" CssClass="btnImage" Text="Send Friend Request" runat="server" OnClick="btnSendFrndReq_Click" /></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
So,I want to do like,when user click on button in front of particular member's name,the data from that row should get store in a table.
I have tried this on button click event ,but it's not working.I am unable to find what is going wrong.I giving the code behind,Please check it,and suggest me any solution
protected void grdviewFriendRequest_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void btnSendFrndReq_Click(object sender, EventArgs e)
{
string fname = "", lname = "";
GridViewRow row = grdviewFriendRequest.SelectedRow;
fname = row.Cells[0].Text;
lname = row.Cells[1].Text;
Int32 frmCandiid = (Int32)(Session["candiID"]);
InsertRegistation frndRq= new InsertRegistation();
Session["candID"] =frndRq.FrndReqGetCandiid(fname, lname);
Int32 toCandiid = (Int32)(Session["candID"]);
frndRq.InsertFrndReq(0, frmCandiid, toCandiid, DateTime.Now);
}
By trying this its not working then i try the following:
protected void grdviewFriendRequest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "SendFriendReq")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = grdviewFriendRequest.Rows[index];
string fname = "", lname = "";
fname = row.Cells[0].Text;
lname = row.Cells[1].Text;
Int32 frmCandiid = (Int32)(Session["candiID"]);
InsertRegistation frndRq = new InsertRegistation();
Session["candID"] = frndRq.FrndReqGetCandiid(fname, lname);
Int32 toCandiid = (Int32)(Session["candID"]);
frndRq.InsertFrndReq(0, frmCandiid, toCandiid, DateTime.Now);
}
}
it still gives me error, saying Input string not in a correct form.
then I try to give commandArgument property,but still it gives me value 0;
<asp:TemplateField HeaderText="Send Friend Request">
<ItemTemplate>
<asp:Button ID="btnSendFrndReq" CssClass="btnImage" Text="Send Friend Request" runat="server" CommandName="SendFriendReq" CommandArgument="<%# Container.DataItemIndex %>" /></ItemTemplate>
</asp:TemplateField>
So,what I can do now?
Thanks in advance.