2014-04-14 52 views
0

如何发送mltiple用户消息使用griview应连接到两个表即登录(从哪里将检索和显示用户名),然后第二个表消息(消息将被存储为特定的用户名)。我已将它连接到登录,但我无法将值插入到消息表中。消息表具有msg_id,用户名和消息列。如何发送多个用户消息使用gridview与模板

这里的设计:

的.aspx

</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"> 
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
    EnableModelValidation="True" DataSourceID="SqlDataSource1" 
    onrowcommand="GridView2_RowCommand"> 
<Columns> 
    <asp:BoundField DataField="username" HeaderText="username" 
     SortExpression="username" /> 
    <asp:BoundField DataField="password" HeaderText="password" 
     SortExpression="password" /> 
    <asp:BoundField DataField="utype" HeaderText="utype" SortExpression="utype" /> 
    <asp:BoundField DataField="ptype" HeaderText="ptype" SortExpression="ptype" /> 
</Columns> 
     </asp:GridView> 
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:AutomobileConnectionString14 %>" 
     SelectCommand="SELECT * FROM [login] WHERE ([utype] LIKE '%' + @utype + '%')"> 
     <SelectParameters> 
     <asp:Parameter DefaultValue="U" Name="utype" Type="String" /> 
     </SelectParameters> 
     </asp:SqlDataSource> 
</asp:Content> 

aspx.cs代码

protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName.Equals("cc")) 
    { 
     TextBox txt1 = (TextBox)GridView2.FooterRow.FindControl("TextBox1"); 
     foreach(GridView gr in GridView2.Rows) 
     { 
      CheckBox chk = (CheckBox)gr.FindControl("CheckBox1"); 
      if (chk.Checked) 
      { 
       Object ob = GridView2.DataKeys[gr.RowIndex].Value; 

      } 

现在我被困她我怎么能值插入另一个表的消息时,它是已连接到登录表。帮助我,我想在这里完成的是发送消息,以检查用户。

+0

是否定义在GridView中的CommandName = “CC”?你完成的方式是不正确的。 – Janty

+0

是的,我在按钮标签中,我给了命令名=“cc”。 – pawar

+0

你想在消息表格中插入消息时,检查一些复选框并提交按钮?对? – Janty

回答

0

如下尝试:

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="userId" 
     OnRowCommand="GridView2_RowCommand" OnRowEditing="GridView2_RowEditing" OnRowUpdated="GridView2_RowUpdated" OnRowUpdating="GridView2_RowUpdating"> 
     <Columns> 

      <asp:TemplateField HeaderText="Username"> 
       <ItemTemplate> 
        <asp:Label Text='<%# Eval("username") %>' runat="server"></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:BoundField DataField="password" HeaderText="password" 
       SortExpression="password" /> 

      <asp:BoundField DataField="utype" HeaderText="utype" SortExpression="utype" /> 
      <asp:BoundField DataField="ptype" HeaderText="ptype" SortExpression="ptype" /> 

      <asp:TemplateField> 
       <ItemTemplate> 
        <asp:Label Text='<%# Eval("messgae") %>' runat="server"></asp:Label> 
       </ItemTemplate> 
       <EditItemTemplate> 
         <asp:TextBox ID="txtMsg" runat="server"></asp:TextBox> 
        </EditItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField> 
       <ItemTemplate> 
        <asp:CheckBox ID="chk" runat="server" /> 
       </ItemTemplate> 

      </asp:TemplateField> 
     </Columns> 

    </asp:GridView> 

在RowDataBound事件被发现的控制来设置邮件编辑文本框。 请参阅复选框上的内联编辑代码。

http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/ http://www.codeproject.com/Articles/23471/Editable-GridView-in-ASP-NET