This is a discussion on ASP.NET Data Controls within the ASP and ASP.NET Programming forums, part of the Web Development category; hey, You should be able to put an inline anchor in your datagrid. The syntax for this is: <a ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hey, You should be able to put an inline anchor in your datagrid. The syntax for this is: <a name="someid">...</a> Usually, you put this anchor around the title of your item, or the contents of the first column in your datagrid. To automatically scroll to this item, then you append #someid to the end of your querystring. You should be able to get this effect with a little javascript glue that executes after the textbox. Good luck!
__________________ J Suresh Kumar Google Hacks ![]() |
| Sponsored Links |
| |||
| hi, Actually, I'm trying to scroll within the DATAGRID, not the screen. Your solution will let me put the cursor on a screen that is ALREADY DRAWN, thanks for your help but this is not the problem. I have a datagrid that displays 10 items at a time, with paging options at the bottom. There are say, 750 items, therefore 75 pages of items. If someone wants to edit a particular record, I don't want them to have to search through all these screens. Is that not a bit of a bulky interface? If a manager wants to investigate a few items that were flagged, they don't want to spend 10 minutes finding that record within a datagrid. I want to be able to enter in a record key and position the DATAGRID to that item, if it's on page 33, then move the datagrid to that page.
__________________ G.A.P |
| |||
| hi, OK. Now I understand you, sorry. Let's say you have a text field where you can enter an index, and next to it a button "Go to". When you press that button, you should set the CurrentPageIndex in code behind and then bind data again. Like this: DataGrid1.CurrentPageIndex = int.Parse(txtPage.Text); DataGrid1.DataBind(); Just make sure you never try to navigate to a page higher than DataGrid.PageCount! Good luck!
__________________ J Suresh Kumar Google Hacks ![]() |
| |||
| Thanks! The problem is slightly different actually, how is the user going to know item # 3248 is on page 37? So I really have to search by ITEM. But if there's no other way (I'm guessing there isn't), I can hook up to the sql object with a dataview, iterate till I find the item #, while keeping track of what page it is on (there will be constant # items per page) and then set the page index that way. (I'm already sorting by item # so the record count should be the same). Thanks for the help.
__________________ G.A.P |
| |||
| hi, It won't be the quickest implementation, but it will do the for you ;-) Another approach: If you know that you always have say 20 items on a page, and you want to go to item 30, then you can calculate the page for that item very easily by dividing the item # with the total number of items per page. Be sure to pick the integral part of the division.
__________________ J Suresh Kumar Google Hacks ![]() |
| |||
| hi suresh, You mean, if your ID sequence was based on incrementing integer or something like that you could do some math and not even have to do a read loop where you counted past a bunch of sorted IDs to determine what page it would fall on. The only reason I have to do a extra read loop is, the IDs will be sorted but not necessarily predictable, 7442-1, 7442-2, 7443-1, 7444-1, 7444-2, 7444-3...
__________________ G.A.P |
| |||
| hi, It was unclear if you meant to enter the actual (database) id of the item in the box, or the sequential number (e.g. item 6 out of 10). If you want to enter the actual id of the item then you would need a little more logic, but if you just wanted to jump to the n:th item, then you could calculate its page.
__________________ J Suresh Kumar Google Hacks ![]() |
| |||
| hi, Generally in a work environment the sequential number is not known to a boss, administrator, etc. They might want to check up on item 766-4, but they will very rarely know (or care) that it's the 42nd item when you sort them by item ID. They just want to know the details on that item id. So I read through the dataset and figure out that since there are 10 items per page, item 766-4 is the 42nd item and will therefore be the 2nd item displaying on page 5. And take them to that particular page of the datagrid and automatically trigger the select on that line #. At any rate, I solved the problem, it works now. I'm posting the code in case someone else has the same problem.. /* * This routine does a search when the user enters an ID and clicks the button. It figures out * what page the item # will fall on, moves to that page, and selects the row to display it in the * detailsview as well */ protected void B_FindSampleID_Click(object sender, EventArgs e) { /* the number of lines per page in the datagrid */ int linesPerPage = 10; int itemIndex = 0; bool foundItem = false; string curId = ""; /* Get entered ID */ string searchId = TB_SearchId.Text.ToString().Trim(); /* * Get a dataview that contains the same data that the grid displays */ DataView ds = (DataView)BriteMeterGrid.Select(DataSourceSelectAr guments.Empty); /* No ID or no data? just return */ if ((ds.Count == 0) || (searchId == "")) { return; } /* * Get the item's sequence #. Just loop through the database until we find a match, * or go past where that item could be. Worse case scenario, if the item is not found * just position the grid at the closest match. */ for (itemIndex = 1; (foundItem == false) && (itemIndex < ds.Count); itemIndex++) { curId = ds.Table.Rows[itemIndex].ItemArray[0].ToString().Trim(); if (string.Compare(curId,searchId, true) >= 0) { foundItem = true; } } if (foundItem == true) { int pageIndex = (itemIndex / linesPerPage); /* move grid to correct page */ GV_BriteMeter.PageIndex = pageIndex; if (curId == searchId) /* exact match? cause a 'select' on that row */ { Session["SelectedBD"] = curId; } } else { GV_BriteMeter.PageIndex = 0; } } /* * Session["SelectedBD"] is used to tell the detailsview control what record to display. * It can also be set by the B_FindSampleID_Click() function. */ protected void GV_BriteMeter_SelectedIndexChanged(object sender, EventArgs e) { Session["SelectedBD"] = GV_BriteMeter.SelectedValue.ToString().Trim(); }
__________________ G.A.P |
| |||
| hey all, How to access the detail gridview in masterDetail gridview in the button click event? can any one help me.... hello all, I have master detail gridview master gridview company and detail gridview is peoplelist, i wanted to implement multiple selection in peoplelist gridview using checkboxes. But i am not sure how to get the datakey (in mycase personid) of all the rows in which the checkbox is selected. I need to do insert operation using these personid's can anyone point me in the right direction. Cheers, I am trying to access the child gridview in this method but not able to do so GridView People = grdCompanyPeople.FindControl("grdPersons")as GridView for (int i = 0; i < People.Rows.Count; i++) { GridViewRow Singlerow = People.Rows[i]; bool isChecked = ((CheckBox)Singlerow.FindControl("chkSelect")).Che cked; if (isChecked == true) { str.Append(People.DataKeys[Singlerow.RowIndex]["PersonID"].ToString() + ","); } } // prints out the result Response.Write(str.ToString()); <asp:GridView ID="grdCompanyPeople" runat="server" AutoGenerateColumns="False" DataKeyNames ="CoDetailID,CoID" OnRowDataBound ="grdCompanyPeople_RowDataBound" SelectedIndex ="0" OnSelectedIndexChanging ="grdCompanyPeople_SelectedIndexChanging" OnRowCreated="grdCompanyPeople_RowCreated" OnRowCommand ="grdCompanyPeople_RowCommand" OnPageIndexChanging ="grdCompanyPeople_PageIndexChanging" PageSize ="2" AllowPaging="True" OnSelectedIndexChanged ="grdCompanyPeople_SelectedIndexChanged" GridLines="Horizontal" Width="100%"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:ImageButton ID="btnDSelect" runat="server" ImageUrl="../images/ok.png" ToolTip="Display Deal Details" CommandArgument='<%# Bind("CoDetailID") %>' OnClick="btnCSelect_Click"/> </ItemTemplate> <ItemStyle VerticalAlign="Top" /> </asp:TemplateField> <asp:TemplateField HeaderText="Company Type"> <ItemTemplate> <table> <tr> <td></td> <td><asp ropDownList ID="ddlCoType" runat="server" CssClass="form"></asp ropDownList><asp:Label ID="DetailID" runat="server" Text='<%# Bind("CoDetailID") %>' Visible="False"></asp:Label></td> <td valign="top"><asp:Label ID="Label2" runat="server" Text="Hired By:" Height="1px" Width="50px"></asp:Label></td> <td valign="top"><asp ropDownList ID="ddlClientList" runat="server" AppendDataBoundItems="true" CssClass="form"><asp:ListItem Text ="Please Select" Value="0" /> </asp ropDownList></td></tr> </table> </ItemTemplate> <ItemStyle Width="10px" VerticalAlign="Top" /> <HeaderStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:TemplateField HeaderText="Company Role"> <ItemTemplate> <asp:TextBox ID="tbCoRole" runat="server" CssClass ="form"></asp:TextBox> </ItemTemplate> <ItemStyle Width="10px" VerticalAlign="Top" /> <HeaderStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:BoundField DataField="Company" HeaderText="Company" > <ItemStyle Width="80px" VerticalAlign="Top" /> <HeaderStyle HorizontalAlign="Center" /> </asp:BoundField> <asp:BoundField DataField="City" HeaderText="City" > <ItemStyle Width="40px" VerticalAlign="Top" /> <HeaderStyle HorizontalAlign="Center" /> </asp:BoundField> <asp:BoundField DataField="State" HeaderText="State" > <ItemStyle Width="20px" VerticalAlign="Top" /> <HeaderStyle HorizontalAlign="Center" /> </asp:BoundField> <asp:BoundField DataField="Country" HeaderText="Country" > <ItemStyle Width="50px" VerticalAlign="Top" /> <HeaderStyle HorizontalAlign="Center" /> </asp:BoundField> <asp:ButtonField ButtonType ="Image" CommandName="Show" ImageUrl="../images/add.png" > <ItemStyle VerticalAlign="Top" /> </asp:ButtonField> <asp:ButtonField ButtonType ="Image" CommandName="Hide" ImageUrl="../images/remove.png" > <ItemStyle VerticalAlign="Top" /> </asp:ButtonField> <asp:TemplateField HeaderText="People List"> <ItemTemplate> <asp:GridView ID="grdPersons" runat="server" AutoGenerateColumns ="False" DataKeyNames ="PersonID" GridLines="Horizontal" HeaderStyle-CssClass="head_1" Width="160px"> <SelectedRowStyle CssClass="Green" /> <HeaderStyle CssClass="Pink" /> <Columns> <asp:TemplateField> <HeaderTemplate> <input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chkSelect" runat="server"/> </ItemTemplate> <ItemStyle Width="5px" /> </asp:TemplateField> <asp:BoundField DataField="FullName" HeaderText="Name" > <ItemStyle Width="150px" /> </asp:BoundField> <asp:BoundField DataField="Title" HeaderText="Job Title" /> </Columns> </asp:GridView> </ItemTemplate> <HeaderStyle HorizontalAlign="Center" /> <ItemStyle VerticalAlign="Top" Width="250px" /> </asp:TemplateField> </Columns> <FooterStyle CssClass="head_1" /> <HeaderStyle CssClass="head_1" /> </asp:GridView> Thanks in Advance for your help |
| |||
| Hi, Because the nested GridView is located in the row of the master GridView, you should get it from each row, not the master GridView, like GridView people = (GridView)grdCompanyPeople.Rows[rowIndex].FindControl("grdPersons"); foreach(GridViewRow row in people.Rows) { if(row.RowType = DataControlRowType.DataRow) { bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked; if (isChecked) { str.Append(People.DataKeys[row.RowIndex]["PersonID"].ToString() + ","); } } } Hope it helps.
__________________ Venkat knowledge is Power |
| |||
| Hi You code seems fine except this line: GridView People = grdCompanyPeople.FindControl("grdPersons") as GridView I think you'll get null reference in this way and it should be: GridView People = grdCompanyPeople.Rows[index].FindControl("grdPersons");//change index to meet your need Another problem is in which event handler did you put your code. If your problem isn't solved, please post more details. Thanks & Regards
__________________ G.A.P |
| |||
| hi, After the user makes the selection using checkboxes and hits the insert button which is present outside the gridview i have to get the selection datakeys for inserting into database, how do i get this index for each row, can you suggest? One more question Allen as the people gridview has paging when i go to the second page the checkboxes selected in the first page are unchecked, so is there a way to maintain the selection during paging. Cheers, Shilpa. GridView people = (GridView)grdCompanyPeople.Rows[Index].FindControl("grdPersons");foreach (GridViewRow row in people.Rows) { if (row.RowType = DataControlRowType.DataRow) { bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked; if (isChecked) { str.Append(People.DataKeys[row.RowIndex]["PersonID"].ToString() + ","); } } |
| |||
| Hi, Is the Insert button located outside the nested gridview but inside the master gridview? I mean if the insert button is in each row of the master GridView. If so, you add Click event hanler to the button like protected void InsertButton_Click(object sender, EventArgs e) { // get the button Button btt = (Button)sender; // get the row where the button is located GridViewRow row = (GridViewRow)btt.NamingContainer; // get the nested GridView GridView People = (GridView)row.FindControl("grdPersons") // add your code here } To the second question. when the PageIndexChanged, the GridView will be rebound to the datasource and the controls will recreated. So the changes will be lost. If you want to keep the values, please save it in viewstate before leaving the current page. Hope it helps.
__________________ Venkat knowledge is Power |
| |||
| Thank you for the reply, I have tried using the viewstate as suggested by you on the gridview (not nested inside another gridview), but still the checkboxes are getting unchecked when i go to the second page, Can you please have a look at this code and tell me what i have done wrong. Cheers, |
| |||
| hey, protected void grdPersons_PageIndexChanging(object sender, GridViewPageEventArgs e) { Response.Write(grdPersons.PageIndex.ToString()); int d = grdPersons.PageCount; string[] texts = new string[grdPersons.PageSize]; CheckBox checkBox; int count = 0; foreach (GridViewRow row in grdPersons.Rows) { checkBox = (CheckBox)row.FindControl("chkSelect");if (checkBox != null) { texts[count] = checkBox.Checked.ToString(); } else { texts[count] = ""; count++; } } Session["page" + grdPersons.PageIndex] = texts; grdPersons.Visible = true; grdPersons.PageIndex = e.NewPageIndex; int RecordCount; DataSet DS = new DataSet();String Cmd = "executing stored procedure " + lblPageCoDetailID.Text; DS = info.SelectDSQuery(Cmd); RecordCount = DS.Tables.Count; if (RecordCount > 0) { grdPersons.DataSource = DS.Tables[0]; grdPersons.DataBind(); } } protected void grdPersons_PreRender(object sender, EventArgs e) { if (Session["page" + grdPersons.PageIndex] != null) { CheckBox checkBox; string[] texts = (string[])Session["page" + grdPersons.PageIndex]; for (int i = 0; i < grdPersons.Rows.Count; i++) { checkBox = (CheckBox)grdPersons.Rows[i].FindControl("chkSelect"); checkBox.Text = texts[i]; checkBox.Checked = convert.StringToBool(texts[1].ToString()); } } }
__________________ Venkat knowledge is Power |
| |||
| Here new features of Dynamic WebForms ,Dynamic DataControls Really interesting http://download.microsoft.com/downlo...taControls.wmv Last edited by kingmaker : 09-06-2007 at 04:24 AM. |
| |||
| Hi, I have two problem here: 1. I want to use popup calendar into gridview while editing. The gridview I have is in <asp:Content> tag not into <from> tag. When user click on edit button in gridview, a link "click" appears with textbox for that column, when click on “click ", a popup calendar appears and as user select particular date; getting following error: Line: 20 Char:1 Error: 'window.opener.form1.txtStartDate' is null or not an object' code: url:...... I have used following code in the <EditItemTemplate> of gridview. <input id="StartDateTextBox" type="text" size="15" value='<%# DataBinder.Eval(Container.DataItem,"Startdate") %>' /> <a href="javascript:calendar_window=window.open('Date Picker.aspx?formname=form1.txtStartDate','calendar _window', 'width=250,height=250');calendar_window.focus()">c lick</a> <br /> Here I have used formname=form1. StartDateTextBox but I dont have form1 'coz I am using master page, all code is into <asp:content> tag. How can I pass textbox without form tag? 2. When I use above code without master page i.e. without <asp:content> tag & with <form> tag; Its working fine But when I add runat="server" into above input control <input id=" StartDateTextBox", again the same error. How to solve this error? Thank you
__________________ Venkat knowledge is Power Last edited by Venkat : 09-10-2007 at 02:24 AM. |