Hi, I have a datagrid with paging. The problem is that if lets say there are 20 pages then instead of the paging appearing as lets say 1,2,3,4,5,6..... it appears as ...,1,2,3,4,5,6. How can i fix it? Thanks
Hi, When i click on the next page number the page is blank although there should be records. Why? Thanks in advance. ASPX.VB Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim isAuth As Boolean = False Dim U_ID As String If Not Page.IsPostBack Then cmd = oConn.CreateCommand cmd.CommandText = "SELECT * , '../EDIT_ADS.aspx?AD_ID=' + CAST(AD_id AS NVARCHAR(16)) AS url_str FROM ybay_mdb...ads ADS WHERE AD_POSTER = @U_ID" cmd.Parameters.Add("@AD_ID", AD_ID.ToString) cmd.Parameters.Add("@U_ID", U_ID) Dim da As New SqlDataAdapter(cmd) DIM dt As New DataTable("ads") da.Fill(dt) DataGrid1.DataSource = dt DataGrid1.DataBind() oConn.Open() Dim dr As SqlDataReader dr = cmd.ExecuteReader() Do While dr.Read Label1.Text = (dr.Item("ad_poster")) Loop End If End Sub Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If e.CommandSource.commandname = "Update" Then Response.Redirect("../practice/databinding.aspx") End If End Sub Sub doPaging(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged DataGrid1.CurrentPageIndex = e.NewPageIndex DataGrid1.CurrentPageIndex = 0 DataGrid1.DataBind() End Sub ASPX: <aspataGrid OnPageIndexChanged="doPaging" id="DataGrid1" runat="server" AutoGenerateColumns="False" allowPaging="True" PagerStyle-HorizontalAlign="Center" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" HorizontalAlign="Right" CssClass="GridHeader" PageSize="3"> <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle> <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle> <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle> <Columns> <asp:BoundColumn DataField="ad_id" HeaderText="מס' מודעה"></asp:BoundColumn> <asp:BoundColumn DataField="ad_title" HeaderText="כותרת"></asp:BoundColumn> <asp:ButtonColumn Text="עדכון מודעה" ButtonType="PushButton" HeaderText="עדכון מודעה" CommandName="Update"></asp:ButtonColumn> </Columns> <PagerStyle HorizontalAlign="Center" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle> </aspataGrid>
Sub doPaging(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged DataGrid1.CurrentPageIndex = e.NewPageIndex 'Very important DataGrid1.DataSource = getDataSource() DataGrid1.DataBind() End Sub Private Function getDataSource() As DataTable Dim cmd As New SqlCommand Dim oConn As New SqlConnection(ConnString comes here) oConn.Open() cmd = oConn.CreateCommand cmd.CommandText = "SELECT * from myTable" Dim da As New SqlDataAdapter(cmd) Dim dt As New DataTable(myTable) da.Fill(dt) oConn.Close() Return dt End Function Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not Page.IsPostBack Then DataGrid1.DataSource = getDataSource() DataGrid1.DataBind() End If End Sub All the rest should be OK HTH.
Hi, Currently I have in my datagrid a itemtemplate colume with a href that is working. However, instead of using itemTemplate i want to use a button but I am not sure how to send the parameters sid &_ID to the next page. Here is my code so far: aspx.vb Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim isAuth As Boolean = False Try sid = Request.QueryString("sid") UD = (US.GetUserDataByGuid(sid)) Catch Response.Redirect("default.asp") End Try If Not UD.IsAdmin Then isAuth = False Response.Redirect("default.asp") End If End Sub Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click If txtSearch.Text = "" Then Response.Write("Enter text") Else fillTable() End If End Sub Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If e.CommandSource.commandname = "Update" Then Response.Redirect("../practice/databinding.aspx") End If If e.CommandSource.commandname = "ShowAll" Then End If End Sub Sub fillTable() U_ID = txtSearch.Text cmd = oConn.CreateCommand cmd.CommandText = "SELECT *, 'UserMsg.aspx?sid=' + @sid +'&'+'U_ID=' + CAST(u_id AS NVARCHAR(16)) AS url_str, (SELECT TOP 1 ad_idnum FROM YBAY_MDB...ADS WHERE ad_poster=users.u_id) AS idnum FROM ybay_mdb...users USERS WHERE U_ID like '%'+@U_ID+'%'" cmd.Parameters.Add("@U_ID", U_ID) cmd.Parameters.Add("@sid", sid) Dim da As New SqlDataAdapter(cmd) Dim dt As New DataTable("ads") da.Fill(dt) DataGrid1.DataSource = dt DataGrid1.DataBind() End Sub ASPX: <asp:datagrid CssClass="GridWidth" id="DataGrid1" runat="server" HorizontalAlign="Right" AutoGenerateColumns="False" BackColor="White" BorderWidth="2px" BorderStyle="Ridge" BorderColor="White" PagerStyle-HorizontalAlign="Center" AllowPaging="True" OnPageIndexChanged="doPaging" CellPadding="3" Width="100%" Height="100%" GridLines="None" CellSpacing="1"> <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#9471DE"></SelectedItemStyle> <ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#E7E7FF" BackColor="#4A3C8C"></HeaderStyle> <FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle> <Columns> <asp:BoundColumn DataField="idnum" HeaderText="ת.ז."></asp:BoundColumn> <asp:TemplateColumn HeaderText ="שם מלא"> <ItemTemplate> <a href ="<%#container.dataitem ("url_str")%>"><%#container.dataitem ("u_first")%><%#container.dataitem ("u_last")%></a> &n
corectly, you are looking for the <asp:ButtonColumn> member of the dataGrid. yse that and choose between PushButton and LinkButton as the ButtonType attribute, add the CommandName and catch the click event in the DataGrid1_ItemCommand to select on e of any Command types, or, in the specific events such as: DataGrid1_DeleteCommand or DataGrid1_CancelCommand etc... HTH.
Hi, Thanks for the reply. I know that i have to do something like the code below. The only problem is that i am not sure how to make the parameters receive the correct u_id and sid. Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If e.CommandSource.commandname = "Update" Then Response.Redirect("../EDIT_ADS.aspx?u_ID=" & u_ID &"&sid="&sid ) End If End Sub aspx: <Columns> <asp:ButtonColumn Text="עדכון מודעה" ButtonType="PushButton" HeaderText="עדכון מודעה" CommandName="Update"></asp:ButtonColumn> </Columns>
Hi, I want the paging to appear as follows: ....10,9,8,7,6,5,4,3,2,1 and not as it appears now which is: 1,2,3,4,5,6,7,8,9,10..... How can i do that? I tried dir=rtl and aligning the text but it doesn't work. Thanks