Gridview附带SqlDataSource控件如何显示运行时更新的数据 [英] Gridview is attached with SqlDataSource control How show runtime updated data
问题描述
创建一个网页,其中两个主要部分为一个输入详细信息部分,另一个为Datagridview.当输入详细信息时,单击按钮.主要问题是gridview并未更改,但请参见Sql Server Data has change> please help在按钮中单击按钮如何在Gridview中同时更改.
Create web pages in which two main section one Entry Detail Section and other is Datagridview . When entry detail click the button.Main problem is gridview is not changing that but when see Sql Server Data has changed >please help How can Get simultanously changed in Gridview in button click .
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoPostBack="True"
DataSourceID="SqlDataSource1" Width="619px" AllowPaging="True"
BackColor="#CCFFCC" CellSpacing="2" Font-Bold="True" Font-Names="Arial"
ForeColor="Black" PageSize="3"
EnableModelValidation="True"
HorizontalAlign="Center"
onselectedindexchanged="GridView1_SelectedIndexChanged"
AllowSorting="True">
<%-- <rowstyle horizontalalign="Center" />--%>
<rowstyle horizontalalign="Center" wrap="False" />
<columns>
<asp:BoundField DataField="Department Name" HeaderText="Department Name"
SortExpression="Department Name" />
<asp:BoundField DataField="Letter Number" HeaderText="Letter Number"
SortExpression="Letter Number" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
<asp:BoundField DataField="Number Deo" HeaderText="Number Deo"
SortExpression="Number Deo" />
<asp:BoundField DataField="Number Month" HeaderText="Number Month"
SortExpression="Number Month" />
</columns>
<HeaderStyle BackColor="#006600" BorderColor="Black" BorderStyle="Double"
BorderWidth="2px" ForeColor="#CCFFCC" />
<alternatingrowstyle width="30px" wrap="True" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:JAPITConnectionString %>"
SelectCommand="SELECT * FROM [vwaskdd]"
ProviderName="<%$ ConnectionStrings:ITConnectionString.ProviderName %>">
然后在按钮中点击
And in Button Click
Gridview1.DataSource = SqlDataSource1;
GridView1.DataBind();
推荐答案
ConnectionStrings:JAPITConnectionString%>" SelectCommand =" ProviderName =" <%
ConnectionStrings:JAPITConnectionString %>" SelectCommand="SELECT * FROM [vwaskdd]" ProviderName="<%
ConnectionStrings:ITConnectionString.ProviderName%>" > span>
ConnectionStrings:ITConnectionString.ProviderName %>">
然后在按钮中点击
And in Button Click
Gridview1.DataSource = SqlDataSource1;
GridView1.DataBind();
//在这里,您无需使用sqldatasource即可手动执行此操作. //点击按钮
//这里是您的插入语句......
//插入后调用此方法
//Here u do it manually without using sqldatasource..
//On click of button
//Here ur insert statement goes.....
// after insert call this method
public DataSet SelectAll()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["JAPITConnectionString "].ConnectionString);
string str = "SELECT * FROM [vwaskdd]";
da = new SqlDataAdapter(str, con);
ds = new DataSet();
da.Fill(ds);
return ds;
}
//当您绑定gridview时,调用此方法
//and when u bind the gridview call this method
private void BindGridview()
{
ds = new DataSet();
ds= classname.SelectAll();
DataTable dt=new DataTable();
dt = ds.Tables[0];
GridView1.Visible = true;
GridView1.DataSource = dt;
GridView1.DataBind();
}
//希望对您有帮助.
//Hope it helps u..
这篇关于Gridview附带SqlDataSource控件如何显示运行时更新的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!