這是怎麼對我的作品。如果你可以試試這個代碼:
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" class="gridview" OnRowCommand="EditGridData" runat="server"
AutoGenerateColumns="False" CellPadding="4" GridLines="None" AllowPaging="True"
OnPageIndexChanging="GrdState_PageIndexChanging" PageSize="20" EmptyDataText="Record is Not Available"
Width="93%">
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton ID="BtnEdit" runat="server" CausesValidation="false" class="black skin_colour round_all"
CommandArgument='<%# Eval("Country_ID")%>' CommandName="Edit1" ForeColor="#6699FF"
Font-Underline="True"> <span>Edit</span></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="BtnDelete" OnClientClick="return confirm('Are you sure want to delete?');"
CausesValidation="false" class="black skin_colour round_all " CommandArgument='<%# Eval("Country_ID")%>'
CommandName="Delete1" runat="server" ForeColor="#6699FF" Font-Underline="True"><span>Delete</span></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:LinkButton ID="LBtnView" CausesValidation="false" class="black skin_colour round_all "
CommandArgument='<%# Eval("Country_ID")%>' CommandName="View1" runat="server"
ForeColor="#6699FF" Font-Underline="True"><span>View</span></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Country_Name" HeaderText="Country" />
<asp:BoundField DataField="Description" Visible="false" HeaderText="Description" />
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<div class="DisplayDiv">
<asp:Label ID="Label1" runat="server" CssClass="DisplayDesc" Text='<%# Eval("Description") %>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CreationDate" HeaderText="Creation Date" DataFormatString="{0:dd/MM/yy}" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
後面的代碼(如果你能看到我使用的命令名稱在網格視圖鏈接按鈕):
public void EditGridData(object sender, GridViewCommandEventArgs e)
{
int i = Convert.ToInt32(e.CommandArgument);
Session["Country_ID"] = i;
if (e.CommandName == "Edit1")
{
SortedList sl = new SortedList();
sl.Add("@mode", "GetRows1");
sl.Add("@Country_ID", i);
SqlDataReader dr = emp.GetDataReaderSP("CountryMaster1", sl);
while (dr.Read())
{
txtCountry.Text = dr["Country_Name"].ToString();
txtDesc.Text = dr["Description"].ToString();
ViewState["Country_Name"] = dr["Country_Name"].ToString();
BtnSubmit.Visible = true;
BtnSubmit.Text = "Update";
}
}
if (e.CommandName == "View1")
{
SortedList sl = new SortedList();
sl.Add("@mode", "GetRows1");
sl.Add("@Country_ID", i);
SqlDataReader dr = emp.GetDataReaderSP("CountryMaster1", sl);
while (dr.Read())
{
txtCountry.Text = dr["Country_Name"].ToString();
txtDesc.Text = dr["Description"].ToString();
ViewState["Country_Name"] = dr["Country_Name"].ToString();
BtnReset.Visible = true;
BtnSubmit.Visible = false;
}
}
if (e.CommandName == "Delete1")
{
SortedList sl = new SortedList();
sl.Add("@mode", "DeleteData");
sl.Add("@Country_ID", i);
emp.ExecuteNonQuerySP("CountryMaster1", sl);
Label1.Visible = true;
Label1.Text = "Record Deleted Successfully…";
BindGrid();
}
}
希望這有助於。
你能解釋你已經發布的代碼是什麼的答案,在這裏發生的問題,使用戶和未來的讀者可以借鑑? –
確定請在一段時間後檢查我編輯的答案。 –