我有一个朋友请求表。在那,我使用网格视图控件来显示所有注册成员,所以想要发送请求的人可以发送请求。我的表单设计代码是:
enter code here
<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>
所以,我想这样做,当用户单击特定成员名称前面的按钮时,该行中的数据应该存储在表中。
我已经在按钮单击事件上尝试过这个,但它不起作用。我无法找到问题所在。我给出了后面的代码,请检查它,并建议我任何解决方案
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);
}
但是在我尝试这个之后
enter code here
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);
}
}
它给了我错误,说输入字符串的格式不正确。
然后我尝试给 commandArgument 属性,但它仍然给我值 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>
并告诉我应该为命令参数提供什么值。
那么,我现在能做什么?