<
radG:GridTemplateColumn
UniqueName
=
"CheckBoxColumn"
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
AutoPostBack
=
"true"
OnCheckedChanged
=
"CheckedChanged"
/>
</
ItemTemplate
>
</
radG:GridTemplateColumn
>
public void CheckedChanged(object sender, EventArgs e)
{
GridDataItem checkedItem = (GridDataItem)(sender as CheckBox).NamingContainer;
string checkedItemIndex = checkedItem.GroupIndex.Substring(checkedItem.GroupIndex.LastIndexOf('_'), 2);
foreach (GridDataItem item in checkedItem.OwnerTableView.Items)
{
string currItemIndex = item.GroupIndex.Substring(item.GroupIndex.LastIndexOf('_'), 2);
if (checkedItem.GroupIndex.StartsWith(item.GroupIndex.Substring(0,1)) && currItemIndex != checkedItemIndex)
{
(item.FindControl("CheckBox1") as CheckBox).Checked = false;
}
}
}
I have a databound grid and am needing to add an additional column that will show a link to a google map for the location designated for the record in each row.
firstly im not sure i am doing this in the correct place, second issue im having (using hard coded parameters) is that the URL is not including these parameter values, the URL just shows the querystring names but none of these has the additional values.
as far as i can see the url format string seems correct and the urlparameters variable is getting the string values set ok, but for some reason they are not replacing the palceholder values in the url.
finally how would i get at the actual datatable values i need once i have this hard coded version working correctly?
heres my code:
Private Sub FillGrid()
Try
Dim gc As GridBoundColumn
Dim glc As GridHyperLinkColumn
glc = New GridHyperLinkColumn
Me.uxGrid.Columns.Add(glc)
glc.HeaderText = "Map"
Dim urlparameters As String()
urlparameters = New String() {"b12jp", "1234", "32.54545", "-2.2342342"}
glc.DataNavigateUrlFields = urlparameters
glc.DataTextFormatString = "{2:D}"
glc.DataTextFormatString = "{3:D}"
glc.DataNavigateUrlFormatString = "GoogleMaps.htm?postcode={0}&id={1}&lat={2}&lng={3}"
glc.UniqueName = ""
glc.ItemStyle.HorizontalAlign = HorizontalAlign.Center
glc.Text = "Map"
glc.HeaderStyle.Width = Unit.Pixel(40)
glc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
For Each col As DataColumn In _myData.Columns
gc = New GridBoundColumn
Me.uxGrid.Columns.Add(gc)
gc.HeaderText = GetCaption(col.ColumnName)
gc.UniqueName = col.ColumnName
gc.DataField = col.ColumnName
gc.Display = True
gc.HeaderStyle.Width = Unit.Pixel(170)
gc.ItemStyle.Wrap = True
Next
Catch ex As Exception
End Try
End Sub
protected void bt_add_Click1(object sender, EventArgs e)
{
Label6.Text = string.Empty;
AddtoList();
Label6.Visible = true;
}
protected void bt_view_Click(object sender, EventArgs e)
{
Gridview();
}
protected void bt_update_Click(object sender, EventArgs e)
{
Update();
clear();
}
protected void btn_reset_Click(object sender, EventArgs e)
{
clearcontrols();
Label6.Text = string.Empty;
}
protected void bt_delete_Click(object sender, EventArgs e)
{
Delete();
txt_Item.Text = string.Empty;
}
protected void StuList_Grid_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
StuList_Grid.CurrentPageIndex = e.NewPageIndex;
StuList_Grid.Visible = true;
SPList taskList = SpListitems();
DataTable tablelist = taskList.Items.GetDataTable();
StuList_Grid.DataSource = tablelist;
StuList_Grid.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion
#region Methods
//This method will display the sharepoint list items to Grid and
//Show listitems in textboxes by id.
private void Gridview()
{
if (txt_Item.Text == string.Empty)
{
try
{
StuList_Grid.Visible = true;
Descending();
StuList_Grid.CurrentPageIndex = 0;
SPList taskList = SpListitems();
DataTable tablelist = taskList.Items.GetDataTable();
StuList_Grid.DataSource = tablelist;
StuList_Grid.DataBind();
Label6.Text = string.Empty;
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('not viewed', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
else
{
StuList_Grid.Visible = false;
SPList taskList = SpListitems();
int id = Convert.ToInt32(txt_Item.Text);
SPListItem item = null;
try
{
item = taskList.GetItemById(id);
}
catch (Exception ex)
{
Label6.Text = "Item doesnot Exist";
}
if (item != null)
{
if (item["StuName"] != null)
{
txt_name.Text = item["StuName"].ToString();
}
else
txt_name.Text = string.Empty;
if (item["Department"] != null)
{
txt_dept.Text = item["Department"].ToString();
}
else
txt_dept.Text = string.Empty;
if (item["Location"] != null)
{
txt_location.Text = item["Location"].ToString();
}
else
txt_location.Text = string.Empty;
if (item["ContactNumber"] != null)
{
txt_number.Text = item["ContactNumber"].ToString();
}
else
txt_number.Text = string.Empty;
Label6.Text = string.Empty;
}
}
}
//This will add textbox values to sharepoint list.
private void AddtoList()
{
try
{
SPList taskList = SpListitems();
SPListItem listitem = taskList.Items.Add();
listitem["StuName"] = txt_name.Text;
listitem["Department"] = txt_dept.Text;
listitem["Location"] = txt_location.Text;
listitem["ContactNumber"] = txt_number.Text;
listitem.Update();
Label6.Text = "Records Saved";
clearcontrols();
Descending();
grid();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('not inserted', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
//This will update the list items by id
private void Update()
{
try
{
if (txt_Item.Text == string.Empty)
{
Label6.Text = "ID value is Required";
}
SPList taskList = SpListitems();
SPListItem item = null;
int id = Convert.ToInt32(txt_Item.Text);
try
{
item = taskList.GetItemById(id);
}
catch (Exception ex)
{
Label6.Text = "Item doesnot Exist";
}
if (item != null)
{
item["StuName"] = txt_name.Text;
item["Department"] = txt_dept.Text;
item["Location"] = txt_location.Text;
item["ContactNumber"] = txt_number.Text;
item.Update();
taskList.Update();
Label6.Text = "Updated";
grid();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('Not Updated', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
//This will delete the list items by id
private void Delete()
{
try
{
if (txt_Item.Text == string.Empty)
{
Label6.Text = "ID value is Required";
}
else
{
SPList taskList = SpListitems();
SPListItem item = null;
int id = Convert.ToInt32(txt_Item.Text);
try
{
item = taskList.GetItemById(id);
}
catch (Exception ex)
{
Label6.Text = "Item Doesnot Exist";
}
if (item != null)
{
item["StuName"] = txt_name.Text;
item["Department"] = txt_dept.Text;
item["Location"] = txt_location.Text;
item["ContactNumber"] = txt_number.Text;
item.Delete();
Label6.Text = "Deleted";
grid();
}
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('Not Deleted', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
//This will return value from method
protected SPList SpListitems()
{
string strDashListRoot = "http://dev02:2000";
SPSite osite = new SPSite(strDashListRoot);
SPWeb oWeb = osite.OpenWeb();
oWeb.AllowUnsafeUpdates = true;
SPList taskList = oWeb.Lists["Name"];
return taskList;
}
//This clear all textboxes and grid
private void clearcontrols()
{
txt_name.Text = string.Empty;
txt_dept.Text = string.Empty;
txt_location.Text = string.Empty;
txt_number.Text = string.Empty;
txt_Item.Text = string.Empty;
StuList_Grid.Visible = false;
}
//This clear all textboxes
private void clear()
{
txt_name.Text = string.Empty;
txt_dept.Text = string.Empty;
txt_location.Text = string.Empty;
txt_number.Text = string.Empty;
txt_Item.Text = string.Empty;
}
//This to bind the grid
private void grid()
{
StuList_Grid.Visible = true;
SPList taskList = SpListitems();
StuList_Grid.CurrentPageIndex = 0;
//StuList_Grid.CurrentPageIndex = StuList_Grid.PageCount - 1;
DataTable tablelist = taskList.Items.GetDataTable();
StuList_Grid.DataSource = tablelist;
StuList_Grid.DataBind();
}
//This will display latest item first in grid id in descending order
private void Descending()
{
GridSortExpression expression = new GridSortExpression();
expression.FieldName = "ID";
expression.SortOrder = GridSortOrder.Descending;
StuList_Grid.MasterTableView.SortExpressions.AddSortExpression(expression);
}
#endregion
}
}