同一页面上的多个Gridview,具有多个GridViewCommandEventArgs, buttonfield从错
本文关键字:GridViewCommandEventArgs buttonfield 从错 一页 Gridview | 更新日期: 2023-09-27 18:15:07
我有这两个gridview。第一个名为'GridView1'正常工作,但第二个名为'Gridview2',当我点击ButtonField从GridView ID列单元格内获取ID,它得到正确的行索引,但从错误的GridView,它从'GridView1'而不是'Gridview2'那里的代码为功能ButtonField是在GridViewCommandEventArgs _RowCommand代码块。我对于我的生活无法弄清楚为什么它从第一个得到它,甚至e.c mandsource (.ID. tostring())说它来自GridView2,但我得到的列ID是从第一个拿起的。这两个GridView是相同的,除了第二个有更多的ButtonFields,是第一个的自定义视图,只有选定的id显示在第二个GridView(GridView2)上。这是我的第一篇文章,非常感谢你的帮助。我试着搜索谷歌,但我的问题似乎太具体了,很难让它更广泛地在网上找到。
c#代码:一些全局变量,如果有帮助的话:
public partial class userArea : System.Web.UI.Page {
static string getCustomView;
static string hash;
static string authNum;
static string addToMyCustomView;
static string getDistinctArray;
static string getFirstName;
static string getLastName;
static string getUsernameToAddToComp;
static string getNotes;
static string getUserSessionStatus;
ASPX Code: Gridview1
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333" PageSize="7"
Width="1344px" onrowcommand="GridView1_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="lheID" HeaderText="ID"
SortExpression="lheID" />
<asp:BoundField DataField="lhewirelessGiant" HeaderText="Wireless Giant"
SortExpression="lhewirelessGiant" />
<asp:BoundField DataField="lheFName" HeaderText="First Name"
SortExpression="lheFName" />
<asp:BoundField DataField="lheInitials" HeaderText="Initials"
SortExpression="lheInitials" />
<asp:BoundField DataField="lheLName" HeaderText="Last Name"
SortExpression="lheLName" />
<asp:BoundField DataField="lhePrimaryEmail" HeaderText="Primary Email"
SortExpression="lhePrimaryEmail" />
<asp:BoundField DataField="lheDisplayName" HeaderText="Display Name"
SortExpression="lheDisplayName" />
<asp:BoundField DataField="lheNameID" HeaderText="Name ID"
SortExpression="lheNameID" />
<asp:BoundField DataField="lheWhosLookingAtThis" HeaderText="Who's looking @ this?"
SortExpression="lheNameID" />
<asp:ButtonField ButtonType="Image" ImageUrl="images/copy.png" CommandName="CopyToMe"
HeaderText="Add to My List" Text="Add to My List" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
ASPX Code: GridView2
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource2" ForeColor="#333333" PageSize="7"
Width="1344px" onrowcommand="GridView2_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="lheID" HeaderText="ID"
SortExpression="lheID" />
<asp:BoundField DataField="lhewirelessGiant" HeaderText="Wireless Giant"
SortExpression="lhewirelessGiant" />
<asp:BoundField DataField="lheFName" HeaderText="First Name"
SortExpression="lheFName" />
<asp:BoundField DataField="lheInitials" HeaderText="Initials"
SortExpression="lheInitials" />
<asp:BoundField DataField="lheLName" HeaderText="Last Name"
SortExpression="lheLName" />
<asp:BoundField DataField="lhePrimaryEmail" HeaderText="Primary Email"
SortExpression="lhePrimaryEmail" />
<asp:BoundField DataField="lheDisplayName" HeaderText="Display Name"
SortExpression="lheDisplayName" />
<asp:BoundField DataField="lheNameID" HeaderText="Name ID"
SortExpression="lheNameID" />
<asp:ButtonField ButtonType="Image" ImageUrl="images/Apply.png" CommandName="Complete"
HeaderText="Complete" Text="Add to My List" />
<asp:ButtonField ButtonType="Image" ImageUrl="images/Display.png" CommandName="AddComputer"
HeaderText="Comp.(+)" Text="Add to My List" />
<asp:ButtonField ButtonType="Image" ImageUrl="images/Text.png" CommandName="AddNotes"
HeaderText="View/Add Notes" Text="Add to My List" />
<asp:ButtonField ButtonType="Image" ImageUrl="images/Info.png" CommandName="Info"
HeaderText="More Info" Text="Add to My List" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
c# Code: GridView1_RowCommand
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string key = e.CommandName;
if (key == "CopyToMe")
{
GridView1.DataBind();
GridView2.DataBind();
int index = int.Parse(e.CommandArgument.ToString());
GridView grid = (GridView)e.CommandSource;
GridViewRow row = grid.Rows[index];
TableCell tblCell = row.Cells[0];
authNum = tblCell.Text;
//update the who is
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("UPDATE lhentries SET lheWhosLookingAtThis = '" + getFirstName + " " + getLastName + "' WHERE lheID = '" + authNum + "' ;");
cmd.Connection = con;
MySqlDataReader reader1 = cmd.ExecuteReader();
reader1.Close();
}
catch (Exception ex)
{
}
addToMyCustomView = null;
//get the custum view from my row
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT lhuCustomeView FROM lhusers WHERE lhUUsername = '" + getUsername.Text + "' AND lhupassword = '" + hash + "';");
cmd.Connection = con;
addToMyCustomView = ((string)cmd.ExecuteScalar());
con.Close(); con.Dispose();
// Response.Write(getCustomView);
}
catch (Exception)
{
}
// Response.Write(addToMyCustomView);
//perform adding string operation
if (addToMyCustomView == null)
{
addToMyCustomView = authNum;
}
else
{
addToMyCustomView = addToMyCustomView + "," + authNum;
}
//update the users custome view
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("UPDATE lhusers SET lhuCustomeView = '" + addToMyCustomView + "' WHERE lhupassword='" + hash.ToString() + "' AND lhuUsername = '" + Session["userSessionU"].ToString() + "' ;");
cmd.Connection = con;
MySqlDataReader reader1 = cmd.ExecuteReader();
reader1.Close();
}
catch (Exception ex)
{
}
//Response.Redirect("userArea.aspx");
GridView1.DataBind();
GridView2.DataBind();
//get rid of duplicates in the array and then update
//make char array to be used as split delimitter for the string
char[] splitOn = { ',' };
//split the string into a array
string[] idElements = addToMyCustomView.Split(splitOn);
//only takes var but, makes the array unique, with no duplicates making it distinct
var temp = idElements.Distinct().ToArray();
//convert the array back into a string delimitted by a comma
string getDistinctArray = String.Join(",", temp);
//FOR TESTING WHAT GETS PULLED FROM THE USERS CUSTOM VIEW
//Response.Write(getDistinctArray.ToString() + "this is the one");
Response.Write(authNum);
//update with distinct array
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("UPDATE lhusers SET lhuCustomeView = '" + getDistinctArray + "' WHERE lhupassword='" + hash.ToString() + "' AND lhuUsername = '" + Session["userSessionU"].ToString() + "' ;");
cmd.Connection = con;
MySqlDataReader reader1 = cmd.ExecuteReader();
reader1.Close();
}
catch (Exception ex)
{
}
GridView1.DataBind();
GridView2.DataBind();
Response.Write(grid.ID.ToString() + " - " + authNum + " - " + index);
}
GridView1.DataBind();
GridView2.DataBind();
}
c# Code: GridView2_RowCommand
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
string key = e.CommandName;
//Add computer
if (key == "AddComputer")
{
//Visuals
temp.Visible = true;
temp.Style.Add("width", "100%");
temp.Style.Add("height", "100%");
temp.Style.Add("top", "0px");
temp.Style.Add("left", "0px");
topPanel.Style.Add("width", "300px");
topPanel.Style.Add("height", "220px");
//topPanel.Style.Add("margin", "0px auto");
//topPanel.Style.Add("margin", "0px auto");
Button2.Visible = true;
addAComputer.Visible = true;
computerTable.Visible = true;
temp.Visible = true;
topPanel.Visible = true;
//Functionality
//////UNRESOLVED: THERE ARE TWO GRIDVIEWS. THE FIRST ONE NAME GRIDVIEW1 WORKS WITHOUT A HITCH, THE SECOND GRIDVIEW NAMES GRIDVIEW2, WHEN THE BUTTONFIELD IS CLICKED THE ROW FOR THE PHYSICAL GRIDVIEW ITSELF, THE INDEX IS OBTAINED CORRECTLY, FOR THE COMMANDSOURCE, WHEN CONVERTING THE ID OF THE COMMANDSOURCE SO AS TO SEE WHICH OF THE GRIDVIEWS THE COMMANDSOURCE IS COMING FROM, THE COMMANDSOURCE SAYS GRIDVIEW2 WHICH IS CORRECT. WHEN THE INDEX OF THE COMMAND ARGUMENT IS USED TO GET THE GRIDVIEWROW, IT DOES GET THE CORRECT ROW, BUT IT'S STILL POINTING TO THE WRONG GRIDVIEW WHICH IS GRIDVIEW1 WHEN IT SHOULD BE GRIDVIEW2
int index = int.Parse(e.CommandArgument.ToString()); // gets the right index(row from the gridview itself)
GridView grid2 = (GridView)e.CommandSource; // saying it gets the right gridview
GridViewRow row = grid2.Rows[index]; //correct row, wrong gridview
TableCell tblCell = row.Cells[0];
authNum = tblCell.Text;
//TEST
//int authNums = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32(e.)].Value);
TableCell place7 = row.Cells[7];
getUsernameToAddToComp = place7.Text;
//Response.Write(getUsernameToAddToComp);
Response.Write(grid2.ID.ToString() + " - " + authNum + " - " + index);
}
if (key == "AddNotes")
{
//Visuals
temp.Visible = true;
temp.Style.Add("width", "100%");
temp.Style.Add("height", "100%");
temp.Style.Add("top", "0px");
temp.Style.Add("left", "0px");
topPanel.Style.Add("width", "300px");
topPanel.Style.Add("height", "220px");
//topPanel.Style.Add("margin", "0px auto");
//topPanel.Style.Add("margin", "0px auto");
addNotesDiv.Visible = true;
notesTable.Visible = true;
notesTable.Style.Add("z-index", "9");
//Functionality
int index = int.Parse(e.CommandArgument.ToString());
GridView grid = (GridView)e.CommandSource;
GridViewRow row = grid.Rows[index];
TableCell tblCell = row.Cells[0];
authNum = tblCell.Text;
//get notes from entries table using authnum if any
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT lheNotes FROM lhentries WHERE lheID = '" + authNum + "' ;");
cmd.Connection = con;
getNotes = ((string)cmd.ExecuteScalar());
con.Close(); con.Dispose();
// Response.Write(getCustomView);
}
catch (Exception)
{
}
//insert notes from db into text box
noteTextBox.Text = getNotes;
getNotes = "";
//TableCell place7 = row.Cells[7];
//getNotes = place7.Text;
//Response.Write(getUsernameToAddToComp);
}
if (key == "Info")
{
int index = int.Parse(e.CommandArgument.ToString());
GridView grid = (GridView)e.CommandSource;
GridViewRow row = grid.Rows[index];
TableCell tblCell = row.Cells[0];
authNum = tblCell.Text;
Session["getIDForMoreInfo"] = authNum;
Response.Redirect("allUserInfo.aspx");
}
if (key == "Complete")
{
//Response.Write("");
GridView2.DataBind();
int index = int.Parse(e.CommandArgument.ToString());
GridView grid = (GridView)e.CommandSource;
GridViewRow row = grid.Rows[index];
TableCell tblCell = row.Cells[0];
authNum = tblCell.Text;
//update the the entry to the status of completed
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("UPDATE lhentries SET lheCompleted = 'True' WHERE lheID = '" + authNum + "'; ");
cmd.Connection = con;
MySqlDataReader reader1 = cmd.ExecuteReader();
reader1.Close();
//this is a test to see if the button is picking up the correct row number
// Response.Write(authNum);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
//GridView2.DataSource = "SqlDataSource2";
GridView2.DataBind();
// Response.Redirect("userArea.aspx");
authNum = null;
}
}
可能是很简单的事情,我只是想多了。如果你能帮忙,谢谢。
所以事实证明,我偶然发现的问题是由于我的页面加载中的某些东西。
protected void Page_Load(object sender, EventArgs e)
{
//Session
if (Session["userSessionU"] == null)
{
Response.Redirect("LHLogin.aspx");
}
else
{
getUsername.Text = Session["userSessionU"].ToString();
}
getUserSessionStatus = Session["userAccountType"].ToString();
//if super admin, show super admin controls
if (getUserSessionStatus == "Super-Admin")
{
adminOptions.Visible = true;
}
else
{
adminOptions.Visible = false;
}
if (!IsPostBack)
{
GridView2.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
GridView2.DataSourceID = "SqlDataSource2";
GridView2.DataBind();
}
//display for divs
// topPanel.Visible = false;
temp.Attributes.CssStyle.Add("opacity", "0.6");
//computerTable.Visible = false;
//refresh gridviews
SqlDataSource2.DataBind();
GridView2.DataBind();
//hash password session string
hash = FormsAuthentication.HashPasswordForStoringInConfigFile(Session["userSessionPW"].ToString() + "", "SHA1");
//get the users last name
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT lhulname FROM lhusers WHERE lhUUsername = '" + getUsername.Text + "' AND lhupassword = '" + hash + "';");
cmd.Connection = con;
getLastName = ((string)cmd.ExecuteScalar());
con.Close(); con.Dispose();
// Response.Write(getCustomView);
}
catch (Exception)
{
}
//get the users first name
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT lhufname FROM lhusers WHERE lhUUsername = '" + getUsername.Text + "' AND lhupassword = '" + hash + "';");
cmd.Connection = con;
getFirstName = ((string)cmd.ExecuteScalar());
con.Close(); con.Dispose();
// Response.Write(getCustomView);
}
catch (Exception)
{
}
try
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["legalHoldConnString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT lhuCustomeView FROM lhusers WHERE lhUUsername = '" + getUsername.Text + "' AND lhupassword = '"+ hash +"';");
cmd.Connection = con;
getCustomView = ((string)cmd.ExecuteScalar());
con.Close(); con.Dispose();
// Response.Write(getCustomView);
}
catch (Exception)
{
}
//clear the customview string
//adv search options for entries
//------ ----------------------
//////////////////////////////////////////////////////////////
searchBtn.Focus();
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lheNameID LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
if (firstNameRB.Checked)
{
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lheFName LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
}
else if (lastNameRB.Checked)
{
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lheLName LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
}
else if (emailRB.Checked)
{
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lhePrimaryEmail LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
}
else if (displayNameRB.Checked)
{
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lheDisplayName LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
}
else if (nameID.Checked)
{
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lheNameID LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
}
else if (whosLookingAtThis.Checked)
{
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lheWhosLookingAtthis LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
}
else if (wirelessGiantRB.Checked)
{
SqlDataSource1.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE (lhewirelessGiant LIKE '%" + searchEntryTable.Text.ToString() + "%' ) ORDER BY lheID DESC";
}
else
{
nameID.Checked = true;
}
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//for my table entries
if (Session["getSearchForMyTable"] != null)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lheNameID LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
if (firstNameRB.Checked)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lheFName LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
}
else if (lastNameRB.Checked)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lheLName LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
}
else if (emailRB.Checked)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lhePrimaryEmail LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
}
else if (displayNameRB.Checked)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lheDisplayName LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
}
else if (nameID.Checked)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lheNameID LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
// Response.Write("this test works if u can se ethis");
}
else if (whosLookingAtThis.Checked)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lheWhosLookingAtthis LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
}
else if (wirelessGiantRB.Checked)
{
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND (lhewirelessGiant LIKE '%" + searchMyTable.Text.ToString() + "%' ) AND lheCompleted = 'False' ORDER BY lheID DESC;";
}
}
if ((getCustomView == null) )
{
//Perform the custom view with the select command
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID = 0 AND lheCompleted = 'False' ORDER BY lheID DESC; ";
}
else
{
try
{
//Perform the custom view with the select command
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND lheCompleted = 'False' ORDER BY lheID DESC; ";
}
catch (Exception ex) { }
}
getCustomView = null;
}
但是主要的问题是在这段代码中:
if ((getCustomView == null) )
{
//Perform the custom view with the select command
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID = 0 AND lheCompleted = 'False' ORDER BY lheID DESC; ";
}
else
{
try
{
//Perform the custom view with the select command
SqlDataSource2.SelectCommand = "SELECT lheID, lhewirelessGiant, lheFName, lheInitials, lheLName, lhePrimaryEmail, lheDisplayName, lheNameID, lheWhosLookingAtthis FROM lhentries WHERE lheID IN (" + getCustomView + ") AND lheCompleted = 'False' ORDER BY lheID DESC; ";
}
catch (Exception ex) { }
}
所以现在我必须找出一个更好的选择语句,以便当自定义视图变为null时,它不会默认到第一个数据源,给外观,它是从不同的数据源采取相同的id。可能不得不使用一些内联脚本,我仍在采取意见,但这应该可能关闭这个问题。