gridview 列的动态绑定 大家好,我数据表中某个字段的内容是这样的:数据库1:xx.xx.xx.xx,应用1:xx.xx.xx.xx ,xx是服务器IP,数据库和应用分别对应2台主机服务器,数据表是GridView,我现在需要单独在字段上做2个连接,分别连接到2台服务器上,怎么做呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不太看得懂。如果都能查询出来的话,显示就可以。用模板列来显示<asp:TemplateField HeaderText="品牌"> <ItemTemplate> <web:lookup ID="ddlBrand" ShowSelect="true" ShowSelectText="未选择" Enabled="false" SelectedValue='<%#Eval("Brand") %>' Width="160px" AutoPostBack="false" Key="ProductBrand" runat="server" msty="blueCircle" /> </ItemTemplate> </asp:TemplateField> <asp:lable id="lbtext" runat="server" text='<%#Eval("字段")%>'/>在repeater的itemdatabind()事件中找到这个字段根据这个字段,查到你想要的内容。 给你个例好看一下 <asp:GridView ID="gridView" runat="server" AllowPaging="True" Width="100%" CellPadding="3" BorderWidth="1px" DataKeyNames="id" OnRowDataBound="gridView_RowDataBound" AutoGenerateColumns="False" PageSize="30" RowStyle-HorizontalAlign="Center" OnRowCreated="gridView_OnRowCreated"> <RowStyle HorizontalAlign="Center"></RowStyle> <Columns> <asp:TemplateField ControlStyle-Width="30" > <ItemTemplate> <%--<asp:CheckBox ID="DeleteThis" onclick="javascript:CCA(this);" runat="server" />--%> </ItemTemplate> <ControlStyle Width="30px"></ControlStyle> </asp:TemplateField> <asp:TemplateField HeaderText="商家名"> <EditItemTemplate> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lbshopname" runat="server" Text='<%# Bind("corpid") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="联系方式"> <ItemTemplate> <asp:Label ID="lbshopphone" runat="server" Text = '<%# Bind("corpid") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="在线邮箱"> <ItemTemplate > <asp:Label ID="lbshopmail" runat="server" Text = '<%# Bind("corpid") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="orderid" HeaderText="订单号" /> <asp:BoundField DataField="productname" HeaderText="产品名称" SortExpression="productname" ItemStyle-HorizontalAlign="Center" > <ItemStyle HorizontalAlign="Center"></ItemStyle> </asp:BoundField> <asp:BoundField DataField="productnum" HeaderText="数量" SortExpression="productnum" ItemStyle-HorizontalAlign="Center" > <ItemStyle HorizontalAlign="Center"></ItemStyle> </asp:BoundField> <asp:BoundField DataField="adddate" HeaderText="下单时间" SortExpression="adddate" ItemStyle-HorizontalAlign="Center" > <ItemStyle HorizontalAlign="Center"></ItemStyle> </asp:BoundField> <asp:BoundField DataField="totalmoney" HeaderText="商品总价" /> <asp:TemplateField HeaderText="状态"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("orderstate") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("orderstate") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> 后台事件是 protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Attributes.Add("style", "background:#FFF"); DataRowView drv = e.Row.DataItem as DataRowView; if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton linkbtnDel = (LinkButton)e.Row.FindControl("LinkButton1"); Label label2 = (Label)e.Row.FindControl("label2"); Label lbshopname = (Label)e.Row.FindControl("lbshopname"); Label lbshopphone = (Label)e.Row.FindControl("lbshopphone"); Label lbshopmail = (Label)e.Row.FindControl("lbshopmail"); if (Convert.ToInt32(drv["orderstate"]) == 0) { label2.Text = "未发货"; } if (Convert.ToInt32(drv["orderstate"]) == 1) { label2.Text = "已发货"; } if (drv["corpid"] != null) { B2BShop.BLL.u_userinfo userinfo = new B2BShop.BLL.u_userinfo(); B2BShop.Model.u_userinfo user = userinfo.GetModel( Convert.ToInt32 (drv["corpid"].ToString())); lbshopname.Text = user.loginname; lbshopphone.Text = user.mobilephone; lbshopmail.Text = user.email; } } } gridview的事件 加一个a标签在一列上就行了。如果你的数据时从2个服务器上取 那么就后台自己组装DataTable 在绑定 请教PostgreSQL参数化查询的参数问题 寻求一函数 数字转型 1111111 --> 1,111,111 毕业设计告一段落, 想问一下,开发小型ERP系统是用C/S架构好还是B/S架构好? 这个是什么回事呢?? 估计思归也很难回答的问题,可扩展的web应用程序模型 用户控件属性赋值问题 如何知道一段话中一段字符的位置 求大神解救~~~~~~~~~~~~~ 无法找到表 0。把ACCESS版修改成SQL的时候,在分类下面出现这样的错误. 求一正则表达式 急.急.在线等解决马上给分.大吓请进..关于实体名作为参数
如果都能查询出来的话,显示就可以。
用模板列来显示<asp:TemplateField HeaderText="品牌">
<ItemTemplate>
<web:lookup ID="ddlBrand" ShowSelect="true" ShowSelectText="未选择" Enabled="false"
SelectedValue='<%#Eval("Brand") %>' Width="160px" AutoPostBack="false" Key="ProductBrand"
runat="server" msty="blueCircle" />
</ItemTemplate>
</asp:TemplateField>
在repeater的itemdatabind()事件中找到这个字段根据这个字段,查到你想要的内容。
BorderWidth="1px" DataKeyNames="id" OnRowDataBound="gridView_RowDataBound"
AutoGenerateColumns="False" PageSize="30"
RowStyle-HorizontalAlign="Center" OnRowCreated="gridView_OnRowCreated">
<RowStyle HorizontalAlign="Center"></RowStyle>
<Columns>
<asp:TemplateField ControlStyle-Width="30" >
<ItemTemplate>
<%--<asp:CheckBox ID="DeleteThis" onclick="javascript:CCA(this);" runat="server" />--%>
</ItemTemplate> <ControlStyle Width="30px"></ControlStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="商家名">
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbshopname" runat="server" Text='<%# Bind("corpid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="联系方式">
<ItemTemplate>
<asp:Label ID="lbshopphone" runat="server" Text = '<%# Bind("corpid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="在线邮箱">
<ItemTemplate >
<asp:Label ID="lbshopmail" runat="server" Text = '<%# Bind("corpid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="orderid" HeaderText="订单号" />
<asp:BoundField DataField="productname" HeaderText="产品名称" SortExpression="productname"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="productnum" HeaderText="数量" SortExpression="productnum"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="adddate" HeaderText="下单时间" SortExpression="adddate"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="totalmoney" HeaderText="商品总价" />
<asp:TemplateField HeaderText="状态">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("orderstate") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("orderstate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> 后台事件是 protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("style", "background:#FFF");
DataRowView drv = e.Row.DataItem as DataRowView; if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton linkbtnDel = (LinkButton)e.Row.FindControl("LinkButton1");
Label label2 = (Label)e.Row.FindControl("label2");
Label lbshopname = (Label)e.Row.FindControl("lbshopname");
Label lbshopphone = (Label)e.Row.FindControl("lbshopphone");
Label lbshopmail = (Label)e.Row.FindControl("lbshopmail");
if (Convert.ToInt32(drv["orderstate"]) == 0)
{ label2.Text = "未发货";
}
if (Convert.ToInt32(drv["orderstate"]) == 1)
{ label2.Text = "已发货";
} if (drv["corpid"] != null)
{ B2BShop.BLL.u_userinfo userinfo = new B2BShop.BLL.u_userinfo();
B2BShop.Model.u_userinfo user = userinfo.GetModel( Convert.ToInt32 (drv["corpid"].ToString()));
lbshopname.Text = user.loginname;
lbshopphone.Text = user.mobilephone;
lbshopmail.Text = user.email;
}
}
}
gridview的事件