如何使用带有模板的gridview发送多个用户消息。 [英] How do I send multiple users message using a gridview with templates.
问题描述
如何使用griview发送mltiple用户消息,该视图应连接到两个表,即登录(从中检索和显示用户名),然后是第二个表消息(其中为特定用户名存储消息) 。我已将其连接到登录但我无法在消息表中插入值。消息表有msg_id,用户名和消息列。
这是设计:
.aspx < br $> b $ b
How do I send mltiple users message using a griview which should be connected to two tables namely login(from where usernames will be retrieved and shown) and then the second table message (where a message is to be stored for particular usernames). I have connected it to login but I am not able to insert values into message table. Message table has msg_id , username and message columns.
Here is the design:
.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代码
aspx.cs code
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;
}
现在我被困了她怎么能把值插入到其他表消息中连接到登录表。帮助我,我想要完成的是向已检查的用户发送消息。
now I am stuck her how can I insert values into other table message when it is already connected to Login table. Help me what I want to accomplish here is send message to checked users.
推荐答案
ConnectionStrings:AutomobileConnectionString14%>
SelectCommand = < span class =code-string> SELECT * FROM [login] WHERE([utype] LIKE'%'+ @utype +'%') >
< SelectParameters>
< asp:参数DefaultValue = U名称= utype Type = String />
< / SelectParameters >
< / asp:SqlDataSource >
< / asp:Content >
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代码
aspx.cs code
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;
}
现在我被困了她怎么能把值插入到其他表消息中连接到登录表。帮助我,我想在这里完成的是向已检查的用户发送消息。
now I am stuck her how can I insert values into other table message when it is already connected to Login table. Help me what I want to accomplish here is send message to checked users.
if (chk.Checked)
{
Object ob = GridView2.DataKeys[gr.RowIndex].Value;
// Here retrieve all required values.
// Connect to Database using SQLConnection class.
// Execute one Update Statement using SQLCommand Class.
}
这篇关于如何使用带有模板的gridview发送多个用户消息。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!